2013-03-26 3 views
0

등의 목록을 가져 와서 API를 다시 구성합니다.Hashmap에 공백이있는 JSON - API에서

JSONArray child = new JSONArray(json.get("children").toString());        
for (int i=0; i<child.length();i++) { 

} 
:

{id="a5b140c9-9987-4e6d-a883-a18c00726883", children=[{id=fe103303-fd5e-4cd6-81a0-a18c00733737, children=[], parentid=a5b140c9-9987-4e6d-a883-a18c00726883, name=Contains Spaces}], parentid=, name=Kiosk} 

그때 나는 반복 아이 물마루 다음 JSONArray의 객체에 공백이있는 경우를 제외하고

내 응용 프로그램 충돌

이는 HashMap의 배열입니다

이 부분은 여기에 공백이 있기 때문에 예외가 있습니다 :

귀하의 메시지 JSON 코드의 첫 번째 조각은 3,745,383,210

D

03-26 10:31:56.409: W/System.err(4793): org.json.JSONException: End of input at character 0 of 
03-26 10:31:56.417: W/System.err(4793):  at org.json.JSONTokener.syntaxError(JSONTokener.java:450) 
03-26 10:31:56.417: W/System.err(4793):  at org.json.JSONTokener.nextValue(JSONTokener.java:97) 
03-26 10:31:56.417: W/System.err(4793):  at org.json.JSONObject.<init>(JSONObject.java:154) 
03-26 10:31:56.417: W/System.err(4793):  at org.json.JSONObject.<init>(JSONObject.java:171) 
03-26 10:31:56.417: W/System.err(4793):  at com.example.tvrplayer.ChannelsDialogPreference$1$1.run(ChannelsDialogPreference.java:158) 
+3

현재 문자열이 유효한 json 문자열이 아닙니다. –

+0

JSON이 올바르지 않습니다. 여기에서 확인하십시오 http://jsonlint.com/ – Naveen

+0

먼저 유효한 json .. { "id": "a5b140c9-9987-4e6d-a883-a18c00726883", ... 그것은 pls가 json을 참조하십시오 같이이어야한다 format –

답변

1

인가? 모든 키와 문자열 값을 ""에 포함시켜야한다는 것을 상기합니다. 그리고 : = 대신이 될해야 같은 :

{"id":"a5b140c9-9987-4e6d-a883-a18c00726883", "children":[{"id":"fe103303-fd5e-4cd6-81a0-a18c00733737", "children":[], "parentid":"a5b140c9-9987-4e6d-a883-a18c00726883", "name":"Contains Spaces"}], "parentid":"", "name":"Kiosk"} 

참조 : 그것은 자바 스크립트 인 경우 JSON Syntax

, 당신은 여전히 ​​(그냥 그 공백, 모든) ""로 문자열 값을 작성해야합니다.