开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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


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

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

查看: 665|回复: 4
收起左侧

[已解决] json取值问题

 关闭 [复制链接]
结帖率:36% (9/25)
发表于 2023-9-22 01:21:02 | 显示全部楼层 |阅读模式   浙江省杭州市
5精币
怎么样写才能把取出来的内容先查找,然后确定位置在取值
比如,我需要先在json中找到name为test111的这个数据,然后在该数据的组中取timeSurvived的值,name是不固定的,比如我输入test111则查找test111,如果我输入test222则查找test222
  
{
"data": {
"type": "match",
"id": "d8fbe5be-7287-4861-b725-609cf0b202de",
"attributes": {
"seasonState": "progress",
"duration": 1483,
"gameMode": "squad-fpp",
"titleId": "bluehole-pubg",
"tags": null,
"isCustomMatch": false,
"createdAt": "2023-09-20T14:55:53Z",
"stats": null,
"shardId": "steam",
"mapName": "Baltic_Main",
"matchType": "official"
},
"relationships": {
"rosters": {
"data": [{
"type": "roster",
"id": "5ec563be-4832-47e4-befb-70ac1eac89de"
}, {
"type": "roster",
"id": "aee349c2-48a9-4e70-8e4d-b05dea18b450"
}, {
"type": "roster",
"id": "27f1d16d-0a59-4901-8f1e-dd6809d21783"
}, {
"type": "roster",
"id": "4c157fa0-d373-4619-b554-2cebfc483f1b"
}, {
"type": "roster",
"id": "fb462b2e-09ef-4830-9e27-45addc35c2e1"
}, {
"type": "roster",
"id": "7595d01d-a836-429c-8edc-e5e860d70f77"
}, {
"type": "roster",
"id": "780e21aa-2884-46a4-b19e-efb29449dc4a"
}, {
"type": "roster",
"id": "6e8edce2-ed2d-44c8-b991-b47590cc09f2"
}, {
"type": "roster",
"id": "5053af37-1319-4a44-956e-1f792d973736"
}, {
"type": "roster",
"id": "c0210e82-8fe1-40c4-b06f-cac13fe5117f"
}, {
"type": "roster",
"id": "698e62a8-b17c-4e99-9258-5ff831501b16"
}, {
"type": "roster",
"id": "5430b385-75e3-4713-8d67-d279448f61db"
}, {
"type": "roster",
"id": "ac19ba81-77fd-48b0-9e1b-cef6ddd0448a"
}, {
"type": "roster",
"id": "1a306f54-95be-429a-b80e-7e8438d76950"
}, {
"type": "roster",
"id": "ca3231bf-ec03-44e2-b387-251d2b8b2de3"
}, {
"type": "roster",
"id": "ee2be3ec-d005-4729-9c06-876b2224700d"
}, {
"type": "roster",
"id": "9f8ac205-5d9d-4ef6-99bc-8ce99fbf64d5"
}, {
"type": "roster",
"id": "976f8617-28be-4b8c-80b6-54e43fc479d2"
}, {
"type": "roster",
"id": "63861837-e802-475a-bc56-11818224e5f1"
}, {
"type": "roster",
"id": "f16328ed-8dd9-4ce2-af47-0ec760ce294c"
}, {
"type": "roster",
"id": "c90059e0-9679-40ed-9b92-292baa1b615d"
}, {
"type": "roster",
"id": "344adf5d-4cd9-4d69-9ffd-df24e9a6b27d"
}, {
"type": "roster",
"id": "ab70efdb-fc3d-49d6-83d4-323c840797a7"
}, {
"type": "roster",
"id": "04763a23-4153-4704-852c-6929401c0456"
}, {
"type": "roster",
"id": "00011920-df27-4391-882b-d8b6e7eda5ee"
}, {
"type": "roster",
"id": "8d205332-18f5-4fa3-89ca-b46ae03ee623"
}, {
"type": "roster",
"id": "5e82c55a-aaed-4c00-8b37-8b7986c28ef1"
}, {
"type": "roster",
"id": "d1e4e64a-3771-4da8-aaf2-67ed02428dbc"
}, {
"type": "roster",
"id": "064d46cf-fb99-4876-9834-8e3dd00eca46"
}, {
"type": "roster",
"id": "aca3cb8e-0b26-4c64-a6a6-0542eac988dd"
}]
},
"assets": {
"data": [{
"type": "asset",
"id": "6be5889d-57c9-11ee-b8fb-aa6df4bcff8f"
}]
}
},
"links": {
"self": "https://api.pubg.com/shards/steam/matches/d8fbe5be-7287-4861-b725-609cf0b202de",
"schema": ""
}
},
"included": [{
"type": "participant",
"id": "edac9449-f107-4aa6-bfa5-eaf2872e97aa",
"attributes": {
"stats": {
"DBNOs": 0,
"assists": 0,
"boosts": 6,
"damageDealt": 0,
"deathType": "byplayer",
"headshotKills": 0,
"heals": 0,
"killPlace": 51,
"killStreaks": 0,
"kills": 0,
"longestKill": 0,
"name": "test111",
"playerId": "account.4aea56508cc14406b1d5038dce4ef9af",
"revives": 0,
"rideDistance": 1605.3445,
"roadKills": 0,
"swimDistance": 0,
"teamKills": 0,
"timeSurvived": 1156,
"vehicleDestroys": 0,
"walkDistance": 1852.3545,
"weaponsAcquired": 5,
"winPlace": 8
},
"actor": "",
"shardId": "steam"
}
}, {
"type": "roster",
"id": "aee349c2-48a9-4e70-8e4d-b05dea18b450",
"attributes": {
"won": "false",
"shardId": "steam",
"stats": {
"rank": 4,
"teamId": 18
}
},
"relationships": {
"team": {
"data": null
},
"participants": {
"data": [{
"type": "participant",
"id": "f1cd1e8d-cae8-4438-b0b6-c55f3c50ce8b"
}, {
"type": "participant",
"id": "168a4591-f881-40d2-823f-8ab8704fa3be"
}, {
"type": "participant",
"id": "3aa63ba2-6122-4a62-8739-8fe9eea8349a"
}, {
"type": "participant",
"id": "d3f8c996-e981-4e02-8223-0315808e67f0"
}]
}
}
}, {
"type": "participant",
"id": "5f6d4853-714a-4299-a119-4e0e3a3db74c",
"attributes": {
"stats": {
"DBNOs": 0,
"assists": 0,
"boosts": 1,
"damageDealt": 0,
"deathType": "byplayer",
"headshotKills": 0,
"heals": 0,
"killPlace": 46,
"killStreaks": 0,
"kills": 0,
"longestKill": 0,
"name": "Isaac21",
"playerId": "account.552aeefc562548c48989c0edba50d440",
"revives": 1,
"rideDistance": 7542.6187,
"roadKills": 0,
"swimDistance": 0,
"teamKills": 0,
"timeSurvived": 1209,
"vehicleDestroys": 0,
"walkDistance": 747.04474,
"weaponsAcquired": 8,
"winPlace": 6
},
"actor": "",
"shardId": "steam"
}
}, {
"type": "participant",
"id": "c0e6ec24-e3c7-42b3-8cb2-5de17a493198",
"attributes": {
"shardId": "steam",
"stats": {
"DBNOs": 0,
"assists": 0,
"boosts": 2,
"damageDealt": 0,
"deathType": "byplayer",
"headshotKills": 0,
"heals": 0,
"killPlace": 82,
"killStreaks": 0,
"kills": 0,
"longestKill": 0,
"name": "Aiy2zui",
"playerId": "account.ca3fb589d802427ab3a98b3b09c420b4",
"revives": 0,
"rideDistance": 0,
"roadKills": 0,
"swimDistance": 0,
"teamKills": 0,
"timeSurvived": 197,
"vehicleDestroys": 0,
"walkDistance": 135.86473,
"weaponsAcquired": 3,
"winPlace": 24
},
"actor": ""
}
}, {
"type": "participant",
"id": "7dfaedf3-7e4c-4a6e-9c1b-eb23095f9678",
"attributes": {
"stats": {
"DBNOs": 0,
"assists": 0,
"boosts": 0,
"damageDealt": 0,
"deathType": "byplayer",
"headshotKills": 0,
"heals": 0,
"killPlace": 89,
"killStreaks": 0,
"kills": 0,
"longestKill": 0,
"name": "Pigeon-king",
"playerId": "account.26ce5dbf3af14176a54fad6615e9f282",
"revives": 0,
"rideDistance": 0,
"roadKills": 0,
"swimDistance": 0,
"teamKills": 0,
"timeSurvived": 169,
"vehicleDestroys": 0,
"walkDistance": 91.13019,
"weaponsAcquired": 4,
"winPlace": 26
},
"actor": "",
"shardId": "steam"
}
}, {
"type": "participant",
"id": "e640d9bd-936f-4934-a20a-d1b4a202166f",
"attributes": {
"stats": {
"DBNOs": 3,
"assists": 2,
"boosts": 8,
"damageDealt": 627.0267,
"deathType": "alive",
"headshotKills": 1,
"heals": 6,
"killPlace": 6,
"killStreaks": 1,
"kills": 4,
"longestKill": 145.19373,
"name": "Alt_GGDD",
"playerId": "account.b8fb8f03c4794be79b1c6a1371a789f5",
"revives": 0,
"rideDistance": 2338.421,
"roadKills": 0,
"swimDistance": 0,
"teamKills": 0,
"timeSurvived": 1483,
"vehicleDestroys": 0,
"walkDistance": 1837.5962,
"weaponsAcquired": 9,
"winPlace": 1
},
"actor": "",
"shardId": "steam"
}
}, {
"type": "participant",
"id": "40aa7db5-2c30-41f6-b7d2-b951f2968e46",
"attributes": {
"stats": {
"DBNOs": 1,
"assists": 0,
"boosts": 0,
"damageDealt": 100,
"deathType": "byplayer",
"headshotKills": 0,
"heals": 0,
"killPlace": 27,
"killStreaks": 1,
"kills": 1,
"longestKill": 34.30928,
"name": "PER_SON1414",
"playerId": "ai.349",
"revives": 0,
"rideDistance": 0,
"roadKills": 0,
"swimDistance": 0,
"teamKills": 0,
"timeSurvived": 1079,
"vehicleDestroys": 0,
"walkDistance": 1819.3186,
"weaponsAcquired": 0,
"winPlace": 15
},
"actor": "",
"shardId": "steam"
}
}, {
"type": "roster",
"id": "698e62a8-b17c-4e99-9258-5ff831501b16",
"attri

最佳答案

查看完整内容

[e=5].版本 2 .局部变量 json, 类_json .局部变量 i, 整数型 json.解析 (#常量1) ' #常量1是你欲解析的内容~ .计次循环首 (json.成员数 (“included”), i) .如果真 (json.取通用属性 (“included[” + 到文本 (i - 1) + “].attributes.stats.name”, ) = “test111”) ' 这里 test111 不是固定的!你可以用变量或者编辑框~ 输出调试文本 (json.取通用属性 (“included[” + 到文本 (i - 1) + “].attribute ...

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

发表于 2023-9-22 01:21:03 | 显示全部楼层   广东省广州市
  
变量名类 型静态数组备 注
json类_json 
i整数型 
json.解析 ( #常量1 )  ' #常量1是你欲解析的内容~
计次循环首 (json.成员数 (“included”), i)
如果真 (json.取通用属性 (“included[”到文本 (i - 1)“].attributes.stats.name”, )“test111”)  ' 这里 test111 不是固定的!你可以用变量或者编辑框~
输出调试文本 (json.取通用属性 (“included[”到文本 (i - 1)“].attributes.stats.timeSurvived”, ))
跳出循环 ()

计次循环尾 ()

评分

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

查看全部评分

回复

使用道具 举报

结帖率:100% (45/45)

签到天数: 4 天

发表于 2023-9-22 08:23:42 | 显示全部楼层   广东省中山市
直接循环取出name和timeSurvived的值不就好了,取出来放列表,不更加一目了然嘛
回复

使用道具 举报

发表于 2023-9-22 08:29:05 | 显示全部楼层   黑龙江省哈尔滨市
  
数组数量 = json.取属性 (“included”).成员数 ()
计次循环首 (数组数量, x)
如果真 (json.取通用属性 (“included[”到文本 (x - 1)“].attributes.stats.name”)“test111”)
调试输出 (json.取属性 (“included[”到文本 (x - 1)“].attributes.stats.timeSurvived”).取数据文本 ())
跳出循环 ()

计次循环尾 ()


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

回复

使用道具 举报

结帖率:94% (16/17)

签到天数: 11 天

发表于 2023-9-22 09:11:28 | 显示全部楼层   黑龙江省哈尔滨市
  
子程序名返回值类型公开备 注
__启动窗口_创建完毕  
JSONcha询取值 ( #常量1," ;test111","timeSurvived")
子程序名返回值类型公开备 注
JSONcha询取值文本型 
参数名类 型参考可空数组备 注
JSON数据文本型要解析的JSON文本
要查的name名文本型test111
要取的同name组中的名文本型timeSurvived
变量名类 型静态数组备 注
JSON类_json 
i整数型 
局_结果文本型 
如果 (JSON.解析 (JSON数据))
计次循环首 (JSON.成员数 (“included”), i)
如果真 (JSON.取通用属性 (“included[”到文本 (i - 1)“].attributes.stats.name”, ) = 要查的name名)
局_结果 = JSON.取通用属性 (“included[”到文本 (i - 1)“].attributes.stats.” + 要取的同name组中的名)
跳出循环 ()

计次循环尾 ()
返回 (局_结果)
返回 (“解析失败”)



补充内容 (2023-9-22 09:20):
这么写,你就可以取name所在的 stats组中的任意值
回复

使用道具 举报

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

本版积分规则 致发广告者

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

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

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