V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
G0D
V2EX  ›  Android

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

  •  
  •   G0D · 2018-03-27 21:55:34 +08:00 · 9300 次点击
    这是一个创建于 2458 天前的主题,其中的信息可能已经有所发展或是发生改变。
    {"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\":[]}}"}
    第 1 条附言  ·  2018-03-27 23:41:19 +08:00
    想到解决办法了。转换成 String,然后通过正则提取数据。
    第 2 条附言  ·  2018-03-29 12:13:37 +08:00
    明白了,多谢各位
    8 条回复    2018-03-28 14:54:23 +08:00
    pdog18
        1
    pdog18  
       2018-03-27 22:39:54 +08:00
    首先它要是一个正常的 Json 字符串
    G0D
        2
    G0D  
    OP
       2018-03-27 23:18:10 +08:00
    @pdog18 就是因为是不正常的所以才不知道怎么处理
    MinQ
        3
    MinQ  
       2018-03-27 23:21:46 +08:00 via Android
    不正常的情况下只能把字符串编辑成正常的才能送 Gson 吧
    prolic
        4
    prolic  
       2018-03-27 23:56:27 +08:00
    最外层 struct Json string,对 Json 再进行一次解析
    xmh51
        5
    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
        6
    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
        7
    cs923  
       2018-03-28 01:24:43 +08:00 via Android
    多了很多转义符号 格式化一下就很清楚了
    vincenttone
        8
    vincenttone  
       2018-03-28 14:54:23 +08:00
    先解一次 json,然后拿字典中 json 对应的字符串再解一次,over
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5295 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 05:45 · PVG 13:45 · LAX 21:45 · JFK 00:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.