如何使用android读取json中的属性值
我想读取json属性值,我的json格式像这样
{"content":{"@attributes" : { "start_limit" : "x","end_limit" : "x","total_records" : "x"},"item":[{"category":"x","distance":"x"}]}},
我想从json属性读取total_record的值。我怎样才能阅读?请帮助我
谢谢 约翰·瑞克
I want to read json attribute value, my json format like this
{"content":{"@attributes" : { "start_limit" : "x","end_limit" : "x","total_records" : "x"},"item":[{"category":"x","distance":"x"}]}},
I want to read total_record's value from json attributes. How can I read ? Please help me
Thanks
John Rick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先检查您的 JSON 字符串。将其更改为
{"content":{"@attributes" : { "start_limit" :"x","end_limit" : "x","total_records" : "x"} },"item":[{"category":"x","distance':"x"}]}}
来自{"content":{"@attributes" : { "start_limit" : "x","end_limit" : "x","total_records" : "x"},"item":[{"category":"x","distance":"x"}]}}
其中您在“item”之前留下了一个右大括号
现在下面是获取“total_records”值的代码
希望您理解这个问题。
First of all check your JSON String.Change it to
{"content":{"@attributes" : { "start_limit" :"x","end_limit" : "x","total_records" : "x"}},"item":[{"category":"x","distance':"x"}]}}
from{"content":{"@attributes" : { "start_limit" : "x","end_limit" : "x","total_records" : "x"},"item":[{"category":"x","distance":"x"}]}}
In which you left one closing curly brace before "item".
Now below is the code to get value of "total_records"
Hope you understand the problem.
只需使用
JSONObject
即可。不能 100% 确定它有效,但它是一个很好的起点。
Simply use
JSONObject
.Not 100% sure it works, but it is a good example where to start.
希望您在提出问题之前已经尝试过。如果没有,这里有一些网址(我用谷歌搜索):
http://www.androidcompetencycenter.com/2009/10/json- parse-in-android/ 和 http:// about-android.blogspot.com/2010/03/androind-json-parser.html
Hope you've already given it a try before asking in SO. If not, here are a few urls (which I googled):
http://www.androidcompetencycenter.com/2009/10/json-parsing-in-android/ and http://about-android.blogspot.com/2010/03/androind-json-parser.html