JSON 数据到 Android 应用程序
我把这部分放在我的 json 对象中。但我无法将其作为 java 列表获取。它给出错误。所以我尝试将它作为一个字符串数组。但还是和以前一样。那么我应该使用什么来解析这些数据以用于我的 Android 应用程序呢?
cuisine: {
-cuisine_names: [
"All (36)"
"Malaysian/ Singaporean (1)"
"Asian (1)"
"Australian (2)"
"Chinese (1)"
"European (3)"
"Spanish (1)"
"Greek (2)"
"Steak House (1)"
"Indian (1)"
"International (7)"
"Thai (1)"
"Italian (8)"
"Modern Australian (7)"
]
-price_ranges: [
"Any Price"
"$0-15"
"$15-30"
"$30+"
]
-times: [
"Any Time"
"05:30PM"
"06:00PM"
"06:30PM"
"07:00PM"
"07:30PM"
"08:00PM"
"08:30PM"
"09:00PM"
"09:30PM"
"10:00PM"
"10:30PM"
"11:00PM"
"11:30PM"
]
}
提前致谢 !
I got this part inside my json object. But I couldn't get this as a java List. It give error. So I tried to take it as a String Array. But it was same as before. So what should I use to parse this data to use with my android application ?
cuisine: {
-cuisine_names: [
"All (36)"
"Malaysian/ Singaporean (1)"
"Asian (1)"
"Australian (2)"
"Chinese (1)"
"European (3)"
"Spanish (1)"
"Greek (2)"
"Steak House (1)"
"Indian (1)"
"International (7)"
"Thai (1)"
"Italian (8)"
"Modern Australian (7)"
]
-price_ranges: [
"Any Price"
"$0-15"
"$15-30"
"$30+"
]
-times: [
"Any Time"
"05:30PM"
"06:00PM"
"06:30PM"
"07:00PM"
"07:30PM"
"08:00PM"
"08:30PM"
"09:00PM"
"09:30PM"
"10:00PM"
"10:30PM"
"11:00PM"
"11:30PM"
]
}
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要使用 JSONObject 填充列表,您应该使用如下函数(其中 NewsBSR 是带有一些基本字段的自定义对象):
To fill a list with a JSONObject, you should use a function like this (where NewsBSR is a custom object with some basic fields):
我想你忘记加逗号了。你可以用这个
http://www.androidcompetencycenter.com/2009/10/json-在android中解析/
I think you have forgotten put commas. And you can use this
http://www.androidcompetencycenter.com/2009/10/json-parsing-in-android/
json 格式不应该是这样的。
首先,应该有一个像这样的代码周围的根对象。
然后数组中的每个字符串之间都需要逗号,如下所示
The json format is not supposed to be like that.
first, there should be a root object surrounding the codes like this.
and then you need commas between every string in the array like so
使用 Gson 非常简单:
输出:
It's very simple with Gson:
output: