모든,내가 GET 매개 변수로 캐릭터 라인 JSON 객체를 전달하기 위해 노력하고있어
는 GET 매개 변수를 json_decode 수 없습니다 만 수신 URL 그것을 해독 할 수없는 것 같다. 여기
는 관련 코드 :클라이언트 측 JSON 객체 제작 (잘 작동) :
function createJson(){
// This works fine. It creates a json objects with three elements, the third being an array.
//(omitted code for brevity)
return jsonData;
}
클라이언트 측 AJAX 호출이 (잘 작동) :
function recordSetGet(jsonData){
request = createRequest();
var rawSet=JSON.stringify(jsonData);
var encodedSet=encodeURIComponent(rawSet);
var params="set="+encodedSet;
var url= "Ajax_recordSetGet.php?"+params;
request.open("GET", url, true);
request.onreadystatechange = function(){}
request.send(null);
}
이쪽을 산출 다음 URL : Ajax_recordSetGet.php?set=%7B%22setTitle%22%3A%22test%22%2C%22setTags%22%3A%22test%20%22%2C%22set%22%3A%5B%7B%22first%22%3A%22Joe%22%2C%22last%22%3A%22Doe%22%2C%22checked%22%3Atrue%7D%5D%7D"
서버 측 치료 :
<?php
header('Content-Type:text/html; charset=UTF-8');
if(!session_id()){
session_start();
}
if(isset($_GET['set'])){
$set=$_GET['set'];//This is the URI encoded string
var_dump ($set);
var_dump (json_decode($set));
var_dump ("Json last error is ".json_last_error());
}
?>
이 var_dumps의 결과는 다음과 같습니다 string '{"setTitle":"test","setTags":"test ","set":[{"first":"Joe","last":"Doe","checked":true}]}"' (length=90)
null
string 'Json last error is 4' (length=20)
는 왜 여기에 실패 json_decode()
입니까? json_last_error()
결과에 구문 오류가 있음을 나타냅니다. 나는 PARAM 문자열을 빌드하는 경우이처럼 인코딩없이
:
편집 : '비 인코딩 된 문자열을 보내는 경우 그 json_decode를 참고하는 것도 실패
var rawSet=JSON.stringify(jsonData);
var params="set="+rawSet;
var url= "Ajax_recordSetGet.php?"+params;
그런 다음 URL은 Ajax_recordSetGet.php?set={"setTitle":"test","setTags":"test ","set":[{"first":"Joe","last":"Doe","checked":true}]}"
수신 URL var_dump에서 동일한 오류가 발생합니다.
string '{"setTitle":"test","setTags":"test ","set":[{"first":"Joe","last":"Doe","checked":true}]}"' (length=90)
null
string 'Json last error is 4' (length=20)
[The SSCCE] (http://sscce.org/)에 대해 알아보십시오. –
** TL; DR **. 질문을보다 간결하게하십시오. 우리가 더 필요하면 우리는 물어볼 것입니다. –
그것은 내가 읽지 않은 많은 코드입니다. –