2016-10-02 101 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格式。 –