json取数据怎么取?求json根据id取数据的java代码
{ "name": "DR", "value": "", "id": "2", "open": false, "icon": null, "children": [ { "name": "1", "value": "", "id": "3", "open": false, "icon": null, "children": [ { "name": "1.1", "value": "", "id": "4", "open": false, "icon": null, "children": [ { "name": "1.1.1", "value": "", "id": "5", "open": false, "icon": null, "children": [ { "name": "检查所见", "value": "1.1.1.1内容", "id": "6", "open": false, "icon": null, "children": null, "target": "", "pId": null, "url": null, "title": null }, { "name": "诊断意见", "value": "1.1.1.2内容", "id": "7", "open": false, "icon": null, "children": null, "target": "", "pId": null, "url": null, "title": null } ], "target": "", "pId": null, "url": null, "title": null } ], "target": "", "pId": null, "url": null, "title": null } ], "target": "", "pId": null, "url": null, "title": null }, { "name": "2", "value": "", "id": "8", "open": false, "icon": null, "children": [ { "name": "2.1", "value": "", "id": "9", "open": false, "icon": null, "children": [ { "name": "2.1.1", "value": "", "id": "10", "open": false, "icon": null, "children": [ { "name": "检查所见", "value": "2.1.1.1内容", "id": "11", "open": false, "icon": null, "children": null, "target": "", "pId": null, "url": null, "title": null }, { "name": "诊断意见", "value": "2.1.1.2内容", "id": "12", "open": false, "icon": null, "children": null, "target": "", "pId": null, "url": null, "title": null } ], "target": "", "pId": null, "url": null, "title": null } ], "target": "", "pId": null, "url": null, "title": null } ], "target": "", "pId": null, "url": null, "title": null } ], "target": "", "pId": null, "url": null, "title": null } 其实是一个Ztree树用到的json! 数据很多,没全部弄出来 格式大概就是这个样, 比如这段json 我要根据id取到 value, 把value值传给前台弹出显示, 比如这段json里给后台传的id为11,value就是 2.1.1.1内容 就这样
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
你这个问题的关键不是如何解析JSON,而是取值方式不对。
你传给后台的id是11,那就在后台只取出该条记录就可以了,为什么还要把整个树形结构的数据都返回来呢。
引用来自“mklop2014”的评论
可以用Gson解析成指定对象
引用来自“mklop2014”的评论
可以用Gson解析成指定对象
我这是json里嵌套数组 反正各种嵌套的 要先一层层解析才行 好纠结额
像数据库那样 根据id查询 value 这种 先解析在根据id查 有类似的代码例子么 ?
回复
如果你传递过来的是标准的json格式,通过fastJson 是可以当成key-value取值的,就跟你用map是一样的
有类似的代码例子么
alibaba 开源的fastjson 是可以的