读取 Json 变量
{"TeamList" : [{"teamid" : "2","teamname" : "Milan"}]}
我如何编写代码来读取 teamid 和 teamname 以便将它们存储在单独的变量中?
请帮忙!
{"TeamList" : [{"teamid" : "2","teamname" : "Milan"}]}
How do i write the code to read the teamid and teamname so as to store them in seperate variables?
Please Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果它是一个 JSON 字符串,则解析它...
然后处理信息
TeamList
是一个数组,因此如果您有多个“团队”,您需要循环遍历它们。If it is a JSON string, parse it...
Then work with the information
TeamList
is an array so if you have more than one "team" you'll need to loop over them.您有一个包含数组
TeamList
的对象,该数组有一个对象作为其元素:You have an object containing an array
TeamList
, which has one object as its elements:如果您发布的示例包含为字符串,您可以使用 javascript 像这样解析它...
然后您可以像这样访问您的数组...
以及 TeamList 中的每一项...
最后假设您在 TeamList 中有一项并且尝试直接回答你的问题......
希望这是有道理的
If the example you have posted in contained as a string you can parse it like so with javascript...
you can then access your array like so...
and each item in TeamList...
finally assuming you have one item in TeamList and making an attemp to directly answers you question...
hope that makes sense
用哪种语言?基本上在使用 json 解析之后,您将对结果执行类似的操作:
result["TeamList"][0]["teamname"]
来获取团队名称和result["TeamList"][ 0]["teamid"]
获取 teamid。in which language? Basically after parsing using json you would do something like this on the result:
result["TeamList"][0]["teamname"]
to get teamname andresult["TeamList"][0]["teamid"]
to get teamid.如果您可以使用 json_decode,如下所示:
If you can use json_decode, like this :
您已将您的问题标记为 jQuery?您想在页面上显示此信息吗?
给定一些示例 html:
和一点 jquery:
将允许您完成此操作。正如其他人指出的那样,如果有多个团队,您将需要迭代该集合。
You had tagged your question as jQuery? We're you wanting to display this information on a page?
Given some sample html:
And a little jquery:
Would allow you to accomplish this. As others have pointed out you would need to iterate over the collection if there were multiple teams.