java 遍历无须json 字符串 获取 节点目录及值数据 5C

{
COSLoginReq = {
1 = [{
index = 1.0,
bytes = [0x8] 3132303030353036,
bytesInfo = [(0, 1), (1, 1), (2, 8 L)],
name = _szAccountID,
value = 12000506
}]
8 = [{
index = 8.0,
bytes = [0x33] 0 A02413112024131180120002A203836...,
bytesInfo = [(63 L, 1), (64 L, 1), (65 L, 51 L)],
name = GlogData,
value = {
GlogData = {
1 = [{
index = 1.0,
bytes = [0x2] 4131,
bytesInfo = [(0, 1), (1, 1), (2, 2 L)],
name = _szChannel,
value = A1
}],
3 = [{
index = 3.0,
bytes = [0x1] 01,
bytesInfo = [(8 L, 1), (9 L, 1)],
name = _nPlatForm,
value = 0x00000001(1 / 1)
}],
2 = [{
index = 2.0,
bytes = [0x2] 4131,
bytesInfo = [(4 L, 1), (5 L, 1), (6 L, 2 L)],
name = _szSubChannel,
value = A1
}],
5 = [{
index = 5.0,
bytes = [0x20] 3836383133333033383734303233392 D...,
bytesInfo = [(12 L, 1), (13 L, 1), (14 L, 32 L)],
name = _strDeviceID,
value = 868133038740239 - ebd24632ac91bfc1
}],
4 = [{
index = 4.0,
bytes = [0x1] 00,
bytesInfo = [(10 L, 1), (11 L, 1)],
name = _bIsSimulator,
value = 0x00000000(0 / 0)
}],
6 = [{
index = 6.0,
bytes = [0x3] 313932,
bytesInfo = [(46 L, 1), (47 L, 1), (48 L, 3 L)],
name = _strMid,
value = 192
}]
}
}
}]
}
}

像这样的一个json 内容不知道的情况下要获取到所有值及值所在的各级节点
期望得到的结果 如key= COSLoginReq-1-index value = 1
其中第三层嵌套的结果期望得到的是
key= COSLoginReq-8-value-GlogData-1-index value = 1

这样的数据 有大神解惑么 我做到第三层嵌套解析就不行乐

作者:qq_25845665
来源:CSDN
原文:https://blog.csdn.net/qq_25845665/article/details/88556876
版权声明:本文为博主原创文章,转载请附上博文链接!

2个回答

用gson java建立对应的实体就可以啦,你把json 拷贝到http://www.bejson.com/json2javapojo/new/ 直接生成对应的类

qq_25845665
qq_25845665 json内容不是固定的 无法生成类 只能用map代替
11 个月之前 回复

第三层用泛型来替代,以后不管是哪个类,就可以直接套用了。
给你看个例子

public class Result<T>
{
    public int code = 2;// 响应结果:1正确,2错误
    public T obj;// 发送对象
    public String msg = "";//描述
    }       

    用这种格式,T只要用对应的类,用gson就可以直接解析json了
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问