json视图中的错误无效json输出


Error in json view invalid json ouput

它说json 无效

{"userDetails":"RefId":565521,{"key":[{"SNO":"565566","Type":"0","Desc":

我想添加RefId,同时包括它说无效的json,请查看并让我知道我的错误的原因

您没有正确写入:

{
"userDetails": [{
    "RefId": 565521, 
    "key": [{"SNO":"565566","Type":"0","Desc":"0"},{"SNO":"12","Type":"1","Desc":"0"}], 
    "success" : true
}] 
}

您的json应该是这样的:

{"userDetails": {"RefId": 565521, "key":[{"SNO":"565566","Type":"0","Desc":"0"},{"SNO":"12","Type":"1","Desc":"0"}]}, "success":true}

你应该这样生成:

$resultJson = array(
    'userDetails' => array(
        'refId' => $reference_id,
        'key' => $arr
    ),
    'success' => true
);
echo json_encode($resultJson);