json_encode()
문자열을 반환 json_encode()
문서에서 :.
Returns a string containing the JSON representation of value.
당신은 JSON 문자열을 구문 분석하는
data
에
JSON.parse()
를 호출하고 객체로 그것을 돌 필요
:
$.post("getSale.php", function(data) {
data = JSON.parse(data);
console.log('data = '+data); // is showing the data with double quotes
}, 'json');
console.log()
호출에서 문자열 data =
을 data
에 연결하고 있으므로 data.toString()
이 기록되며 이는 객체의 문자열 표현()을 반환합니다. 따라서 data
을 별도의 console.log()
호출에 기록하려고합니다. 다음과 같이 입력하십시오 :
$.post("getSale.php", function(data) {
data = JSON.parse(data);
console.log('data = '); // is showing the data with double quotes
console.log(data);
}, 'json');
최신 버전의 jQuery에서 올바른 MIME 유형을 사용하면 JSON이 자동으로 구문 분석됩니다. –
너 다 남자 !!!!! – Catfish
@Matthew +1, 아직도 이해할 수있는 문자열이기 때문에이 점을 이해합니다. MIME 형식이 잘못되었다고 생각합니다. – Alex