2017-05-14 23 views
0

我想顯示一個解析的JSON與我的價值觀。我的意思是,我想給json添加一些值並顯示它。我可以顯示所有響應的結果,但我想顯示只是JSON與我的價值觀並不是所有的數據:)如何把一個值提取JSON並顯示它

這裏我有媒體鏈接解析的json

的JSONObject的JSONObject =新的JSONObject(adresUrl);

  JSONArray offerResources = jsonObject.getJSONArray("offerResources"); 
      for(int y = 0; y < offerResources.length(); y++){ 
       JSONObject currentTransfer = offerResources.getJSONObject(y); 

       JSONArray meetPoint = currentTransfer.getJSONArray("meetPoints"); 
       for (int i = 0; i < meetPoint.length(); i++){ 
        JSONObject currentMeetPoints = meetPoint.getJSONObject(i); 

        String startAddress = currentMeetPoints.getString("startAddress"); // here i wanna put some values , but i dont know how 

//這裏是一個利特爾一塊的json :)

"meetPoints": [ 
    { 
     "startAddress": "....", // after the collon i have to put my value . 
     "startLocation": { 

感謝您的幫助

回答

0

我不知道如果我完全理解你的問題,但是從我到這裏是一些解決方案。我只是創建了一個字符串和幾個Json對象和jsonarray,用於添加值列表並將其放入主json對象「jsonValueObject」中,並將其存儲在meetPoints中。

Accumulate(String key,Object Value)是一個鍵值對,表示如果創建了鍵,則檢查Object是否爲數組,如果此數組具有「值」,則會添加其他新數組創建。如果密鑰存在,「Put」將替換該值。

String jsonString = "{\"results\":[{\"Country\":\"value\",\"state\":\"value\" }, 
{ \"Country\":\"value\", \"state\":\"value\"}]}"; 


JSONObject meetPoints = new JSONObject(jsonDataString); 
JSONObject jsonValueObject = new JSONObject(); 
JSONArray list = new JSONArray(); 
jsonValueObject.put("Country", "newValue"); 
jsonValueObject.put("state", "newValue"); 
jsonValueObject.put("city", "Chennai"); 
jsonValueObject.put("street", "Bharathiyar Street"); 
jsonValueObject.put("date", "14May2017"); 
jsonValueObject.put("time", "10:00AM"); 
list.put(jsonValueObject); 
meetPoints.accumulate("values", list); 
System.out.println(meetPoints); 
+0

謝謝你迅速回答,但我搞砸了我的問題。我的意思是別的。我想要顯示我的json,但只是提取值。例如,在「startAddress」我有如下值:巴黎,紐約,柏林,如果用戶在startAddress「巴黎」寫入,則屏幕上應顯示json與價值巴黎。 –

相關問題