怎么用 Gson 处理特殊的 Json 数组

2018-03-27 21:55:34 +08:00
 G0D
{"json":"{\"flw\":{\"base\":{\"brd\":\"9\",\"brdNm\":\"沃\",\"calLvl\":\"4\",\"calLvlNm\":\"港澳台通话\",\"credit\":\"0\",\"cty\":\"510\",\"netTyp\":\"02\",\"netTypNm\":\"3G\",\"opnDtTm\":\"20160905174939\",\"payTyp\":\"1\",\"payTypNm\":\"预付费\",\"prdId\":\"16164699\",\"prdNm\":\"(OCS)微信沃派畅视卡\",\"prv\":\"051\",\"rmSts\":\"3\",\"rmStsNm\":\"国内漫游\",\"simCrd\":\"8986011692510125080\",\"sts\":\"0\",\"tel\":\"123456789\",\"usrSts\":\"开通\",\"vpnNm\":\"OCS 业务\"},\"i2g\":null,\"i3g\":{\"bgnDt\":\"20180301\",\"endDt\":\"20180327\",\"inf\":[{\"bil\":\"6630.56\",\"extLev\":\"0.00\",\"extOvr\":\"1\",\"extOvrNm\":\"已使用完\",\"extUse\":\"0.00\",\"pkgLev\":\"0.00\",\"pkgOvr\":\"1\",\"pkgUse\":\"1024.00\",\"ttl\":\"300091.45\"}],\"sts\":\"0\"},\"i4g\":{\"inf\":[],\"sts\":\"0\"},\"pkg\":{\"bgnDt\":\"20180301\",\"endDt\":\"20180326\",\"inf\":[{\"lev\":\"4981.77\",\"ttl\":\"11304.00\",\"typ\":\"01\",\"typNm\":\"上网流量\",\"use\":\"6322.23\"},{\"lev\":\"259.00\",\"ttl\":\"260.00\",\"typ\":\"02\",\"typNm\":\"语音电话\",\"use\":\"1.00\"}],\"sts\":\"0\"},\"rc\":null},\"msg\":{\"errMsg\":[],\"promptMsg\":[{\"msgID\":\"MOL03501I\",\"msgTxt\":\"流量查询成功。\"}],\"warnMsg\":[]}}"}
8822 次点击
所在节点    Android
8 条回复
pdog18
2018-03-27 22:39:54 +08:00
首先它要是一个正常的 Json 字符串
G0D
2018-03-27 23:18:10 +08:00
@pdog18 就是因为是不正常的所以才不知道怎么处理
MinQ
2018-03-27 23:21:46 +08:00
不正常的情况下只能把字符串编辑成正常的才能送 Gson 吧
prolic
2018-03-27 23:56:27 +08:00
最外层 struct Json string,对 Json 再进行一次解析
xmh51
2018-03-27 23:59:13 +08:00
这个应该就是一个很标准的 json 字符串啊
我猜测 String aaa=xx.get("json) Object=Gson.xxx(aaa)
能说下这个是怎么的不正常法?

{
"flw": {
"base": {
"brd": "9",
"brdNm": "沃",
"calLvl": "4",
"calLvlNm": "港澳台通话",
"credit": "0",
"cty": "510",
"netTyp": "02",
"netTypNm": "3G",
"opnDtTm": "20160905174939",
"payTyp": "1",
"payTypNm": "预付费",
"prdId": "16164699",
"prdNm": "(OCS)微信沃派畅视卡",
"prv": "051",
"rmSts": "3",
"rmStsNm": "国内漫游",
"simCrd": "8986011692510125080",
"sts": "0",
"tel": "123456789",
"usrSts": "开通",
"vpnNm": "OCS 业务"
},
"i2g": null,
"i3g": {
"bgnDt": "20180301",
"endDt": "20180327",
"inf": [{
"bil": "6630.56",
"extLev": "0.00",
"extOvr": "1",
"extOvrNm": "已使用完",
"extUse": "0.00",
"pkgLev": "0.00",
"pkgOvr": "1",
"pkgUse": "1024.00",
"ttl": "300091.45"
}],
"sts": "0"
},
"i4g": {
"inf": [],
"sts": "0"
},
"pkg": {
"bgnDt": "20180301",
"endDt": "20180326",
"inf": [{
"lev": "4981.77",
"ttl": "11304.00",
"typ": "01",
"typNm": "上网流量",
"use": "6322.23"
}, {
"lev": "259.00",
"ttl": "260.00",
"typ": "02",
"typNm": "语音电话",
"use": "1.00"
}],
"sts": "0"
},
"rc": null
},
"msg": {
"errMsg": [],
"promptMsg": [{
"msgID": "MOL03501I",
"msgTxt": "流量查询成功。"
}],
"warnMsg": []
}
}
lianyue
2018-03-28 00:00:34 +08:00
JSON.parse(({"json":"{\"flw\":{\"base\":{\"brd\":\"9\",\"brdNm\":\"沃\",\"calLvl\":\"4\",\"calLvlNm\":\"港澳台通话\",\"credit\":\"0\",\"cty\":\"510\",\"netTyp\":\"02\",\"netTypNm\":\"3G\",\"opnDtTm\":\"20160905174939\",\"payTyp\":\"1\",\"payTypNm\":\"预付费\",\"prdId\":\"16164699\",\"prdNm\":\"(OCS)微信沃派畅视卡\",\"prv\":\"051\",\"rmSts\":\"3\",\"rmStsNm\":\"国内漫游\",\"simCrd\":\"8986011692510125080\",\"sts\":\"0\",\"tel\":\"123456789\",\"usrSts\":\"开通\",\"vpnNm\":\"OCS 业务\"},\"i2g\":null,\"i3g\":{\"bgnDt\":\"20180301\",\"endDt\":\"20180327\",\"inf\":[{\"bil\":\"6630.56\",\"extLev\":\"0.00\",\"extOvr\":\"1\",\"extOvrNm\":\"已使用完\",\"extUse\":\"0.00\",\"pkgLev\":\"0.00\",\"pkgOvr\":\"1\",\"pkgUse\":\"1024.00\",\"ttl\":\"300091.45\"}],\"sts\":\"0\"},\"i4g\":{\"inf\":[],\"sts\":\"0\"},\"pkg\":{\"bgnDt\":\"20180301\",\"endDt\":\"20180326\",\"inf\":[{\"lev\":\"4981.77\",\"ttl\":\"11304.00\",\"typ\":\"01\",\"typNm\":\"上网流量\",\"use\":\"6322.23\"},{\"lev\":\"259.00\",\"ttl\":\"260.00\",\"typ\":\"02\",\"typNm\":\"语音电话\",\"use\":\"1.00\"}],\"sts\":\"0\"},\"rc\":null},\"msg\":{\"errMsg\":[],\"promptMsg\":[{\"msgID\":\"MOL03501I\",\"msgTxt\":\"流量查询成功。\"}],\"warnMsg\":[]}}"}).json)

这是很正常的 json 吧 json 嵌套了下 json
cs923
2018-03-28 01:24:43 +08:00
多了很多转义符号 格式化一下就很清楚了
vincenttone
2018-03-28 14:54:23 +08:00
先解一次 json,然后拿字典中 json 对应的字符串再解一次,over

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/441943

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX