我的request 在新的1.1.56.android中tojson没有被正确处理,json string如下:

remote request {"indexPhrase":[["确定","确认","是的","好的","没错","可以","对的","行的"],["别了","停止","取消","不对","不行","不好","不是","算了","不要"]],"jsonObject":{"sel_index_phrase":[{"$ref":"$.indexPhrase"},{"$ref":"$.indexPhrase"}]},"paramType":"TYPE_MULTI_SELECTION"}

在1.2.24正式版中,如下:

remote request {"indexPhrase":[["确定","确认","是的","好的","没错","可以","对的","行的"],["别了","停止","取消","不对","不行","不好","不是","算了","不要"]],"jsonObject":{"sel_index_phrase":[{"$ref":"$.indexPhrase[0]"},{"$ref":"$.indexPhrase[1]"}]},"paramType":"TYPE_MULTI_SELECTION"}

显然android版本的循环引用逻辑出了问题,json 没有被正确的序列化。

相关测试code如下:

public class FastJsonTest {

private static final String TAG = "FastJsonTest";

@Test

public void testParseJson() throws InterruptedException {

List a = Arrays.asList("确定", "确认", "是的", "好的", "没错", "可以", "对的", "行的");

List b = Arrays.asList("别了", "停止", "取消", "不对", "不行", "不好", "不是", "算了", "不要");

List c = new ArrayList<>();

c.add(a);

c.add(b);

Request e = new Request("TYPE_MULTI_SELECTION", c);

String request = JSON.toJSONString(e);

Log.e(TAG, " remote request " + request);

Request request1 = null;

try {

request1 = JSON.parseObject(request, Request.class);

} catch (Exception ex) {

Log.e(TAG, "error : ", ex);

}

Log.e(TAG, "request1 = " + JSON.toJSONString(request1));

}

public static class Request implements Serializable {

public String paramType;

public JSONObject jsonObject = new JSONObject();

public Request(){

}

public Request(String paramType, List extends List> list) {

this.paramType = paramType;

if (null != list) {

jsonObject.put("sel_index_phrase", list);

}

}

public List extends List> getIndexPhrase() {

Object phrases = jsonObject.get("sel_index_phrase");

if (null != phrases) {

return (List extends List>) phrases;

} else {

return new ArrayList<>();

}

}

}

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐