2016-10-02 100 views
-4

我在閱讀json數據時遇到問題。我嘗試了一些方法,但總結不全。歡迎任何幫助。這裏是代碼:Json沒有從列表中獲取數據

它現在糾正與整個文件。

"gallery": { 
      "106x100": [ 
      "106x100-0.jpeg", 
      "106x100-1.jpeg", 
      "106x100-2.jpeg", 
      "106x100-3.jpeg", 
      "106x100-4.jpeg", 
      "106x100-5.jpeg", 
      "106x100-6.jpeg", 
      "106x100-7.jpeg", 
      "106x100-8.jpeg", 
      "106x100-9.jpeg", 
      "106x100-10.jpeg", 
      "106x100-11.jpeg", 
      "106x100-12.jpeg", 
      "106x100-13.jpeg", 
      "106x100-14.jpeg", 
      "106x100-15.jpeg", 
      "106x100-16.jpeg" 
      ], 
      "190x100": [ 
      "190x100-0.jpeg", 
      "190x100-1.jpeg", 
      "190x100-2.jpeg", 
      "190x100-3.jpeg", 
      "190x100-4.jpeg", 
      "190x100-5.jpeg", 
      "190x100-6.jpeg", 
      "190x100-7.jpeg", 
      "190x100-8.jpeg", 
      "190x100-9.jpeg", 
      "190x100-10.jpeg", 
      "190x100-11.jpeg", 
      "190x100-12.jpeg", 
      "190x100-13.jpeg", 
      "190x100-14.jpeg", 
      "190x100-15.jpeg", 
      "190x100-16.jpeg" 
      ] 
     }, 
     }, 
+0

你用什麼語言閱讀json? –

+0

我正在使用java – zomlaaa95

+0

@ zomlaaa95:分享您編寫的代碼,以便我們告訴您需要糾正的問題。 – Nishit

回答

2

你的json的格式是錯誤的。

下面是正確的格式:

{"190x100": [ 
      "190x100-0.jpeg", 
      "190x100-1.jpeg", 
      "190x100-2.jpeg", 
      "190x100-3.jpeg", 
      "190x100-4.jpeg", 
      "190x100-5.jpeg", 
      "190x100-6.jpeg", 
      "190x100-7.jpeg", 
      "190x100-8.jpeg", 
      "190x100-9.jpeg", 
      "190x100-10.jpeg", 
      "190x100-11.jpeg", 
      "190x100-12.jpeg", 
      "190x100-13.jpeg", 
      "190x100-14.jpeg", 
      "190x100-15.jpeg", 
      "190x100-16.jpeg" 
      ]} 

PS:讀您使用的是Java。你可以試試這個:

String jsonString = "{"+json+"}"; //pass json here if you are getting it in that format. 
    JSONObject jsonObject = new JSONObject(jsonString); 
    JSONObject newJSON = jsonObject.getJSONObject("gallery"); 
    System.out.println(newJSON.toString()); 

這個格式又是錯誤的。格式如下:

{"gallery": { 
      "106x100": [ 
      "106x100-0.jpeg", 
      "106x100-1.jpeg", 
      "106x100-2.jpeg", 
      "106x100-3.jpeg", 
      "106x100-4.jpeg", 
      "106x100-5.jpeg", 
      "106x100-6.jpeg", 
      "106x100-7.jpeg", 
      "106x100-8.jpeg", 
      "106x100-9.jpeg", 
      "106x100-10.jpeg", 
      "106x100-11.jpeg", 
      "106x100-12.jpeg", 
      "106x100-13.jpeg", 
      "106x100-14.jpeg", 
      "106x100-15.jpeg", 
      "106x100-16.jpeg" 
      ], 
      "190x100": [ 
      "190x100-0.jpeg", 
      "190x100-1.jpeg", 
      "190x100-2.jpeg", 
      "190x100-3.jpeg", 
      "190x100-4.jpeg", 
      "190x100-5.jpeg", 
      "190x100-6.jpeg", 
      "190x100-7.jpeg", 
      "190x100-8.jpeg", 
      "190x100-9.jpeg", 
      "190x100-10.jpeg", 
      "190x100-11.jpeg", 
      "190x100-12.jpeg", 
      "190x100-13.jpeg", 
      "190x100-14.jpeg", 
      "190x100-15.jpeg", 
      "190x100-16.jpeg" 
      ] 
     } 
     } 
+0

它沒有錯,它只是一個文件。 – zomlaaa95

+0

@ zomlaaa95請張貼整個JSON不是一塊。 –

+0

@ zomlaaa95再次糾正了json格式。 –