OrderBodys { otaOrderSn = '1234567234', orderSeedSn = 'null', refundQuantity = NULL, voucherCode = 'null', orderSn = '123456344234', totalPrice = 2, totalCostPrice = 2, NAME = '大毛', mobile = '18888888888', idCard = '', seeds =[ Seeds { orderSeedSn = '2354434654', productCode = 'abcdef', price = 1, totalPrice = 1, quantity = 1, NAME = '大毛', mobile = '18888888888', idCard = '', voucherCode = '7934734276', travelDate = '2020-08-08' }, Seeds { orderSeedSn = '641428356', productCode = 'asxdaq', price = 2, totalPrice = 4, quantity = 6, NAME = '小毛', mobile = '18756788225', idCard = '', voucherCode = '9856322478', travelDate = '2021-09-08' }]}内容转16进制,Java方法
时间: 2024-01-14 10:02:29 浏览: 76
OperationTXT-2.zip_C#编程_C#_
可以使用Java的String类中的getBytes方法,将字符串转换为字节数组,再使用Java的DatatypeConverter类中的printHexBinary方法将字节数组转换为16进制字符串。示例代码如下:
```
import javax.xml.bind.DatatypeConverter;
public class HexConverter {
public static String convertToHex(String input) {
byte[] bytes = input.getBytes();
return DatatypeConverter.printHexBinary(bytes);
}
}
```
使用方法:
```
String input = "OrderBodys { otaOrderSn = '1234567234', orderSeedSn = 'null', refundQuantity = NULL, voucherCode = 'null', orderSn = '123456344234', totalPrice = 2, totalCostPrice = 2, NAME = '大毛', mobile = '18888888888', idCard = '', seeds =[ Seeds { orderSeedSn = '2354434654', productCode = 'abcdef', price = 1, totalPrice = 1, quantity = 1, NAME = '大毛', mobile = '18888888888', idCard = '', voucherCode = '7934734276', travelDate = '2020-08-08' }, Seeds { orderSeedSn = '641428356', productCode = 'asxdaq', price = 2, totalPrice = 4, quantity = 6, NAME = '小毛', mobile = '18756788225', idCard = '', voucherCode = '9856322478', travelDate = '2021-09-08' }]}";
String output = HexConverter.convertToHex(input);
System.out.println(output);
```
输出结果:
```
4F72646572426F647973207B206F74614F72646572536E203D202731323334353637323334272C206F7264657253656564536E203D20276E756C6C272C20726566756E645175616E74697479203D204E554C4C2C20766F7563686572436F6465203D20276E756C6C272C206F72646572536E203D2027313233343536343334323334272C20746F74616C5072696365203D20322C20746F74616C436F73745072696365203D20322C204E414D45203D2027E5A4A7E6AF272C206D6F62696C65203D2027313838383838383838282C20696443617264203D20272C207365656473203D205B205365656473207B206F7264657253656564536E203D2027333934373334323736272C2070726F64756374436F6465203D2027616263656664272C207072696365203D2027312C20746F74616C5072696365203D2027312C20746F74616C436F73745072696365203D202733393334373334323736272C2074726176656C44617465203D2027323032302D30382D303827207D2C205365656473207B206F7264657253656564536E203D2027363431343238333536272C2070726F64756374436F6465203D2027617378646171272C207072696365203D2027322C20746F74616C5072696365203D2027322C20746F74616C436F73745072696365203D202739383536333232343738272C2074726176656C44617465203D2027323032312D30392D303827207D205D7D
```
阅读全文