如何解析android的这个JSON阵列? [英] How to parse this JSON Array in android?

查看:122
本文介绍了如何解析android的这个JSON阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  发送和JSON解析Android中



修改:最后,我找到了答案,通过使用的Iterator 来获取数组值不键值。我刚从这个想法<一个href=\"http://stackoverflow.com/questions/8515018/getting-the-string-value-from-a-json-arrays-object-in-java\">link

我只是新手,以JSON解析了,我不知道如何解析这个还挺 JSONArray 。谁能给我一个提示?

  { 页:
      image1.jpg
      image2.jpg
  ]
}


解决方案

您已经了解JSON的基本概念。

{} 有关实例会谈(所谓的JSONObject)
有关出头(Android中称为JSONArray),其中的[]数组会谈
XXX:YYY键左右功放与谈判;值

首先,你可以让答复JSON字符串变成一个JSONObject的,的JSONObject replyJSON =新的JSONObject(回复)

然后,得到回答的JSONObject内JSONArray命名为页, JSONArray pagesArray = replyJSON.getJSONArray(页面)

最后,该方法的getString ,在你的榜样,您可以使用pagesArray.getString获得JSONArray内的值(0)和pagesArray.getString(1)

检查出更多的细节的文档:
JSONArray

Possible Duplicate:
Sending and Parsing JSON in Android

EDIT: Finally I found an answer to get array value without key value by using Iterator. I just got an idea from this link

I am just newbie to JSON Parsing, and I have no idea how to parse this kinda JSONArray. Can anyone give me a hint ?

{

 "pages": [
      "image1.jpg",
      "image2.jpg"
  ]
}

解决方案

You have to understand the basic concepts of JSON .

{} talks about an instance (called JSONObject) [] talks about an array of somethings (called JSONArray in Android) "xxx":"yyy" talks about key & value

First, you may let the reply json string become an JSONObject, JSONObject replyJSON = new JSONObject(reply)

Then, get the JSONArray named 'pages' inside the replied JSONObject, JSONArray pagesArray = replyJSON.getJSONArray("pages")

Finally, get the value inside the JSONArray by the method getString, in your example, you may use pagesArray.getString(0) and pagesArray.getString(1)

Check out the documentation for more details: JSONArray

这篇关于如何解析android的这个JSON阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆