[英]How can I parse this JSONArray/JSONObject like this?
I have JSON data like this: 我有这样的JSON数据:
"books": [
{
"rating": {},
"subtitle": "",
"author": [
"The OReilly Java Authors"
],
"pubdate": "2003-9",
"tags": [],
"origin_title": "",
…… …… …… …… … …
and I want get the author data,some "author"data has more than one author,but I just confused weather I could parse it like this: 并且我想获取作者数据,一些“作者”数据有多个作者,但是我很困惑,我可以这样解析它:
JSONArray jsonbooks = mess.getJSONArray("books");
for(blabla){
JSONObject obj = jsonbooks.getJSONObject(i);
obj.getJSONArray("author").get(1):
or 要么
JSONArray jsonbooks = mess.getJSONArray("books");
for(blabla){
JSONObject obj = jsonbooks.getJSONObject(i);
obj.getString("author");
sencond way,I could get the data like"["author,blabla "],I want get rid off [" "],and I need more string processing,if there a better way looks like the first way? 第二种方法,我可以得到像“ [” author,blabla“]这样的数据,我想摆脱[”“],并且我需要更多的字符串处理,如果有更好的方法看起来像第一种方法呢?
Since author is an array therefore first convert that into jsonArray 由于author是一个数组,因此首先将其转换为jsonArray
JSONArray jsonAuthor = mess.getJSONArray("author");
then String author = jsonAuthor.get(0); //this will give you -> The OReilly Java Authors
First one is right just one change obj.getJSONArray("author").getString(0):
第一个是正确的,只是一个更改obj.getJSONArray("author").getString(0):
JSONArray jsonbooks = mess.getJSONArray("books");
for(blabla){
JSONObject obj = jsonbooks.getJSONObject(i);
obj.getJSONArray("author").getString(0):
Hope this helps: 希望这可以帮助:
JSONArray jsonAuthorNode = booksJsonObject.optJSONArray("author");
int jsonArrLen = jsonAuthorNode.length();
for(int j=0;j<jsonArrLen;j++)
{
String authorName = jsonAuthorNode.get(j);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.