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

时间:2015-02-17 14:10:08

标签: php json

它表示无效的json

{" userDetails":" RefId":565521,{" key":[{" SNO":" 565566& #34;"类型":" 0""说明":" 0"},{" SNO" :" 12","输入":" 1"," Desc":" 0"}]},& #34;成功":真}

我想添加RefId,同时包括它说无效的json请看,让我知道我错了

2 个答案:

答案 0 :(得分:0)

你的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);

答案 1 :(得分:0)

你没有正确写出来:

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