开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 247|回复: 11
收起左侧

[已解决] JSON多层嵌套解析问题

 关闭 [复制链接]
结帖率:100% (2/2)
发表于 2024-10-25 20:04:44 | 显示全部楼层 |阅读模式   四川省成都市
20精币
一个JSON的解析问题,具体是这个JSON有3个组,每个组又嵌套几个组!这3个组不固定,有可能出现1个组,有可能出现2个组,我想在结果中排除vip组,然后的到usable_count值最大这个小组里面的参数
{"btn_status":1,"btn_text":"请选择","code":1,"data":[{"usable_count":251,"max_price":"320.00","min_price":"150.00","region":1,"list":[{"usable_count":15,"price":"150.00","estate":1,"name":"101","id":1},{"usable_count":44,"price":"150.00","estate":2,"name":"102","id":2},{"usable_count":48,"price":"220.00","estate":31,"name":"131","id":31}],"name":"南面"},{"usable_count":31,"max_price":"888.00","min_price":"888.00","region":3,"list":[{"usable_count":13,"price":"888.00","estate":1,"name":"VIP1","id":1},{"usable_count":17,"price":"888.00","estate":3,"name":"VIP3","id":3}],"name":"VIP"},{"usable_count":22,"max_price":"150.00","min_price":"100.00","region":6,"list":[{"usable_count":35,"price":"100.00","estate":3,"name":"503","id":3},{"usable_count":24,"price":"120.00","estate":20,"name":"520","id":20},{"usable_count":3,"price":"100.00","estate":21,"name":"521","id":21},{"usable_count":22,"price":"100.00","estate":22,"name":"522","id":22},{"usable_count":54,"price":"150.00","estate":35,"name":"535","id":35}],"name":"顶层看台"}],"msg":"获取成功","max_num":2,"type_code":1}  这是格式1
{"btn_status":1,"btn_text":"请选择","code":1,"data":[{"usable_count":1,"max_price":"888.00","min_price":"888.00","region":3,"list":[{"usable_count":"1","price":"888.00","estate":1,"name":"VIP1","id":1}],"name":"VIP"},{"usable_count":1,"max_price":"100.00","min_price":"100.00","region":6,"list":[{"usable_count":"1","price":"100.00","estate":5,"name":"505","id":5},{"usable_count":37,"price":"100.00","estate":6,"name":"506","id":6},{"usable_count":55,"price":"100.00","estate":7,"name":"507","id":7},{"usable_count":62,"price":"120.00","estate":8,"name":"508","id":8}],"name":"南面"}],"msg":"获取成功","max_num":2}这是格式2

{"btn_status":1,"btn_text":"请选择","code":1,"data":[{"usable_count":1,"max_price":"150.00","min_price":"150.00","region":1,"list":[{"usable_count":"1","price":"150.00","estate":4,"name":"104","id":4},{"usable_count":388,"price":"150.00","estate":8,"name":"108","id":8},{"usable_count":360,"price":"180.00","estate":9,"name":"109","id":9},{"usable_count":434,"price":"180.00","estate":10,"name":"110","id":10}],"name":"北面"},{"usable_count":2,"max_price":"888.00","min_price":"888.00","region":3,"list":[{"usable_count":"1","price":"888.00","estate":1,"name":"VIP1","id":1},{"usable_count":"1","price":"888.00","estate":3,"name":"VIP3","id":3}],"name":"VIP"}],"msg":"获取成功","max_num":2}这是格式3


{"btn_status":1,"btn_text":"请选择","code":1,"data":[{"usable_count":1,"max_price":"150.00","min_price":"150.00","region":1,"list":[{"usable_count":"1","price":"150.00","estate":4,"name":"104","id":4},{"usable_count":388,"price":"150.00","estate":8,"name":"108","id":8},{"usable_count":360,"price":"180.00","estate":9,"name":"109","id":9},{"usable_count":434,"price":"180.00","estate":10,"name":"110","id":10}],"name":"北面"},{"usable_count":2,"max_price":"888.00","min_price":"888.00","region":3,"list":[{"usable_count":"1","price":"888.00","estate":1,"name":"VIP1","id":1},{"usable_count":"1","price":"888.00","estate":3,"name":"VIP3","id":3}],"name":"VIP"}],"msg":"获取成功","max_num":2}这是格式4

最佳答案

查看完整内容

usable_count 自己加进去 我就打印了名字和价格

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳
结帖率:100% (5/5)

签到天数: 13 天

发表于 2024-10-25 20:04:45 | 显示全部楼层   河南省焦作市

usable_count 自己加进去 我就打印了名字和价格

评分

参与人数 1荣誉 +1 收起 理由
笨潴 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

结帖率:100% (2/2)

签到天数: 16 天

 楼主| 发表于 2024-10-25 20:06:33 | 显示全部楼层   四川省成都市
目前自己写就写出来这个
  
子程序名返回值类型公开备 注
_按钮1_被单击  
变量名类 型静态数组备 注
json类_json 
i整数型 
比较值整数型 
name文本型 
usable_count文本型 
price文本型 
比较值 = 1
json.解析 ( #全部, , )
计次循环首 (json.成员数 (“data[0].list”), i)
如果真 (到整数 (json.取属性 (“data[0].list[”到文本 (i - 1)“]['usable_count']”).取数据文本 ()) > 比较值)
比较值 = 到整数 (json.取属性 (“data[0].list[”到文本 (i - 1)“]['usable_count']”).取数据文本 ())
name = json.取通用属性 (“data[0].list[”到文本 (i - 1)“].name”, )
usable_count = json.取属性 (“data[0].list[”到文本 (i - 1)“]['usable_count']”).取数据文本 ()
price = json.取通用属性 (“data[0].list[”到文本 (i - 1)“].price”, )

计次循环尾 ()
计次循环首 (json.成员数 (“data[2].list”), i)
如果真 (到整数 (json.取属性 (“data[2].list[”到文本 (i - 1)“]['usable_count']”).取数据文本 ()) > 比较值)
比较值 = 到整数 (json.取属性 (“data[2].list[”到文本 (i - 1)“]['usable_count']”).取数据文本 ())
name = json.取通用属性 (“data[2].list[”到文本 (i - 1)“].name”, )
usable_count = json.取属性 (“data[2].list[”到文本 (i - 1)“]['usable_count']”).取数据文本 ()
price = json.取通用属性 (“data[2].list[”到文本 (i - 1)“].price”, )

计次循环尾 ()
调试输出 (name, usable_count, price)


i支持库列表   支持库注释   
spec特殊功能支持库

回复

使用道具 举报

结帖率:100% (2/2)

签到天数: 16 天

 楼主| 发表于 2024-10-25 20:09:29 | 显示全部楼层   四川省成都市

用的精易模块

json解析测试.e

953.3 KB, 下载次数: 1

回复

使用道具 举报

结帖率:100% (5/5)

签到天数: 13 天

发表于 2024-10-25 22:25:52 | 显示全部楼层   河南省焦作市
自己看看

Desktop.zip

38.44 KB, 下载次数: 2

售价: 1 枚 精币  [记录]

回复

使用道具 举报

结帖率:100% (2/2)

签到天数: 16 天

 楼主| 发表于 2024-10-25 23:20:24 | 显示全部楼层   四川省成都市

大哥,我是想要排除VIP哪一组之后,再比较其他两个组的小组成员,这两个组的小组成员之中那一个的usable_count值最大,便取这个小组的name, usable_count, price
回复

使用道具 举报

结帖率:100% (2/2)

签到天数: 16 天

 楼主| 发表于 2024-10-25 23:32:35 | 显示全部楼层   四川省成都市
bh8cxf 发表于 2024-10-25 23:20
大哥,我是想要排除VIP哪一组之后,再比较其他两个组的小组成员,这两个组的小组成员之中那一个的usable_ ...

您看看格式3和格式4,打印出来没有排除vip哪一组
回复

使用道具 举报

结帖率:100% (5/5)

签到天数: 13 天

发表于 2024-10-25 23:37:36 | 显示全部楼层   河南省焦作市
bh8cxf 发表于 2024-10-25 23:20
大哥,我是想要排除VIP哪一组之后,再比较其他两个组的小组成员,这两个组的小组成员之中那一个的usable_ ...

看下是不是这个样子的。。。。。。。。

Desktop.zip

38.43 KB, 下载次数: 2

售价: 1 枚 精币  [记录]

回复

使用道具 举报

结帖率:100% (5/5)

签到天数: 13 天

发表于 2024-10-25 23:39:33 | 显示全部楼层   河南省焦作市
1752328925 发表于 2024-10-25 23:37
看下是不是这个样子的。。。。。。。。

你要比较内层list的值 还是外层的啊
回复

使用道具 举报

结帖率:100% (2/2)

签到天数: 16 天

 楼主| 发表于 2024-10-25 23:50:00 | 显示全部楼层   四川省成都市
1752328925 发表于 2024-10-25 23:39
你要比较内层list的值 还是外层的啊

先排除外层的vip组,再取内层的来比较,要考虑外层VIP组有时会出现,有时不出现!比如{"btn_status":1,"btn_text":"请选择","code":1,"data":[{"usable_count":1,"max_price":"150.00","min_price":"150.00","region":1,"list":[{"usable_count":"1","price":"150.00","estate":4,"name":"104","id":4},{"usable_count":388,"price":"150.00","estate":8,"name":"108","id":8},{"usable_count":360,"price":"180.00","estate":9,"name":"109","id":9},{"usable_count":434,"price":"180.00","estate":10,"name":"110","id":10}],"name":"北面"},{"usable_count":2,"max_price":"888.00","min_price":"888.00","region":3,"list":[{"usable_count":"1","price":"888.00","estate":1,"name":"VIP1","id":1},{"usable_count":"1","price":"888.00","estate":3,"name":"VIP3","id":3}],"name":"VIP"}],"msg":"获取成功","max_num":2}这一格式的,北面最多的usable_count值是434,就取这一组

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表