2014-04-04 2 views
0

JSON 배열 문자열을 가져 오기 위해 요청 서버를 보내고있는 프로젝트에서 작업 중입니다. 내가 하나의 JSON 배열 목록 문자열을 만들려면 다음 자바 코드를 사용하고 있습니다.JSON 배열 문자열을 구문 분석 할 수 없습니다.

[{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}‚{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}‚{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}‚{"duration":12222‚"height":12‚"widht":12‚"filePath":30‚"format":123‚"bitRate":1111‚"exe":"m"}] 

나는 다음과 같이 구문 분석 jQuery를 사용하고 때 :

클라이언트 측에
JSONArray itemList = new JSONArray(); 
for(int i =0; i<4; i++) { 
    String exe = "m"; 
    final JSONObject jsonObj = new JSONObject(); 
    jsonObj.put("filePath", 30); 
    jsonObj.put("duration", 12222); 
    jsonObj.put("bitRate", 1111); 
    jsonObj.put("widht", 12); 
    jsonObj.put("format", 123); 
    jsonObj.put("height", 12); 
    jsonObj.put("exe", exe); 
    JSONObject jObject = new JSONObject(); 

    try { 
     itemList.put(jsonObj); 
     // jObject.put("itemList", itemList); 
    } catch (Exception e) { 
     System.out.println("ERROR"); 
    } 
} 
return itemList.toString(); 

, AJAX 응답에서, 나는 방법보다 사용하여 다음과 같은 문자열을 얻고있다

$jQ.each($jQ.parseJSON(responseJSON), function(idx, obj) { 
    alert(obj.filePath); 
}); 

JS 오류가 발생했습니다 JSON.parse: expected property name or '}'

왜이 오류가 발생하는지 알 수 없습니다. uring.

+1

이 JSON에서 실수가있다, 당신은 그것을 OBJ ... 당신이 자바 스크립트가 필요하지 않은 이유는 점점 – Defoncesko

+0

JSON을 볼 수 당신의 JSON 여기 -> http://jsonlint.com/ 붙여 넣기 구문 분석 할 것입니다 – VostanAzatyan

+0

JSON이 유효하지 않습니다 ... – VostanAzatyan

답변

1

jsonlint.com에 따르면 값을 ""에 넣어야합니다. 때문에 그냥 처음 몇 줄을보고 특수 문자 &

1

:

[{"duration":12222&sbquo;"height":12&sbquo;

이 유효 JSON으로 표시되지 않습니다. duration이 키이고 값은 Integer12222이지만이 잘못된 json 데이터를 만드는 int 옆에 문자열 데이터 &sbquo;이 있습니다.

데이터를 혼합 한 경우 데이터를 큰 따옴표로 묶어서 문자열로 처리하십시오.


업데이트

,&sbquo;로 인코딩 된 HTML이다 - 당신의 문제가있다.

이 JSON 문자열을 시도해보십시오

[ 
    { 
     "duration": 12222, 
     "height": 12, 
     "widht": 12, 
     "filePath": 30, 
     "format": 123, 
     "bitRate": 1111, 
     "exe": "m" 
    }, 
    { 
     "duration": 12222, 
     "height": 12, 
     "widht": 12, 
     "filePath": 30, 
     "format": 123, 
     "bitRate": 1111, 
     "exe": "m" 
    }, 
    { 
     "duration": 12222, 
     "height": 12, 
     "widht": 12, 
     "filePath": 30, 
     "format": 123, 
     "bitRate": 1111, 
     "exe": "m" 
    }, 
    { 
     "duration": 12222, 
     "height": 12, 
     "widht": 12, 
     "filePath": 30, 
     "format": 123, 
     "bitRate": 1111, 
     "exe": "m" 
    } 
] 

이 지금의 유효성을 검사합니다.

+0

그 html 인코딩 소스가 있습니까? 내가 찾은 온라인 도구는 HTML을 쉼표로 ‚으로 인코딩하지 않으며, 코드를 쌌다면 , –

+0

http://www.w3.org/wiki/Common_HTML_entities_used_for_typography (한 개의 낮은 인용문) - 아마도 틀렸을 것입니다. 틀린 쉼표? – Latheesan

+0

어쩌면 그것은 그것을 대체하고 있습니다 ... –

0

Java 환경이 배열을 잘못 직렬화하고 있습니다.

대신 ‚ - 단일 하단 견적 U + 201A 대신 쉼표 (, U + 002C)가 있어야합니다. 행위에서

관련 문제