2013-10-25 75 views
0

嗨值我是新來的android開發,我想提取JSON數組值可以請你指導我。如何提取JSON數組

這裏是我的JSON

[ 
    { 
     "Id": "c0f3310b-5ec2-4af0", 
     "UserId": "fd83ca17-41f5-472a", 
     "ProfileId": "100006690", 
     "ProfileType": "facebook", 
     "ProfileDate": "/Date(1380894956000)/", 
     "ProfileStatus": 1 
    }, 
    { 
     "Id": "6954433d-b78e-47b6", 
     "UserId": "fd83ca17-41f5-8efe", 
     "ProfileId": "100004492", 
     "ProfileDate": "/Date(1380894685000)/", 
     "ProfileStatus": 1, 
     "ProfileType": "facebook" 
    } 
] 

謝謝

+2

發表你已經嘗試過 – Raghunandan

+0

嘗試搜索現有的線程,然後如果你找不到任何時間發佈在這裏。因爲我覺得有已經線程很多的這一個,可以幫助您解決problem.- – blitzen12

+1

[查看如何在谷歌搜索?](http://bit.ly/17hmgKC) – SilentKiller

回答

0

像下面的編碼

JSONArray jObject = new JSONArray(jsoninputstring); 
     for (int i = 0; i < jObject.length(); i++) { 
      JSONObject obj = jObject.getJSONObject(i); 

      String name= obj.getString("Id"); 
      String email= obj.getString("UserId"); 
      String image= obj.getString("ProfileId"); 
     } 

這裏是JSON教程解析

http://lakyrana.blogspot.in/

http://www.androidhive.info/2012/01/android-json-parsing-tutorial/

http://androidexample.com/JSON_Parsing_-_Android_Example/index.php?view=article_discription&aid=71&aaid=95

+1

聯繫,可以張貼評論。張貼一些細節 – Raghunandan

+0

@Raghunandan燁發佈 – Hariharan

+0

謝謝老兄,它的工作原理 – Gajendran

0

創建新JSONArray對象,並遍歷它。

JSONArray arr = new JSONArray(jsonString); 
for(int i=0;i<arr.length;i++){ 
    JSONObject obj = arr.getJSONObject(i); 
    // read data from obj using obj.getString method. 
} 
0
JSONArray categories = responseData.getJSONArray("categories"); // your JSON array 
    for(int i=0; i < categories.length(); i++){ 
     JSONObject ob = (JSONObject) categories.get(i); 
     ob.getString("Id"); 
     ob.getString("UserId"); // and so on 
} 
0

我強烈建議你檢查出JacksonParser ......你可以從this link下載jar文件,你可以很容易地找到了這麼多例子,如何使用它。這是JSON解析成目標的最簡單和最快的方式。

0
JSONArray jsonArray = new JSONArray(yourResponseString); 
for(int i=0;i<jsonArray.length();i++){ 

     JSONObject dataObject=dataArray.getJSONObject(i); 

      String ID=dataObject.getString("Id"); 
      String UserID=dataObject.getString("UserId"); 
      String ProfileID = jsonObject.getString("ProfileId"); 
       .. 
}