Код: Выделить всё
CreateOrderRequest req = new CreateOrderRequest();
req.pid=1111;
req.name="xxx";
TMemoryBuffer mem_buf = new TMemoryBuffer(512);
TJSONProtocol bin_proto = new TJSONProtocol(mem_buf,true);
try
{
req.write(bin_proto);
System.out.println("====begin serial json=================");
String jsonStr=mem_buf.toString("utf-8");
System.out.println("after jasonprocol="+jsonStr);
System.out.println("====begin deserial json=================");
CreateOrderRequest req2 = new CreateOrderRequest();
TMemoryBuffer mem_buf2 = new TMemoryBuffer(512);
byte[] data = jsonStr.getBytes();
mem_buf2.write(data);
TJSONProtocol bin_proto2 = new TJSONProtocol(mem_buf2,true);
req2.read(bin_proto2);
System.out.println("after de jasonprocol pid="+req.pid);
System.out.println("after de jasonprocol name="+req.name);
}
catch(Exception e)
{
System.out.println(e);
}
Код: Выделить всё
====begin serial json=================
after jasonprocol={"pid":{"i32":1111},"uid":{"i32":0},"corpId": {"i32":0},"sharePriceE6":{"i64":0},"shareCount":{"i32":0},"totalPriceE6":{"i64":0},"bankcardId":{"i32":0},"name":{"str":"xxx"},"isAnonymous":{"tf":0},"expectIncomeE6":{"i64":0},"clientId":{"i32":0},"totalAmtE6":{"i64":0},"subSrc":{"str":""}}
====begin deserial json=================
org.apache.thrift.protocol.TProtocolException: Unexpected character:p
Если для поля NamesAsString_ не установлено значение true, то jasonStr< /code> становится {"1": {"i32":1111},"2":{"i32":0},"3":{"i32":0},... и может быть записан обратно в CreateOrderRequest, я не думаю, что это разумно.
Вы можете записать объект в строку json, но не можете прочитать его обратно?
Подробнее здесь: https://stackoverflow.com/questions/384 ... esasstring
Мобильная версия