使用php创建json输出

时间:2017-02-04 12:37:20

标签: php json

到目前为止,我有这个:

if (is_request_var('requestor') == 'PPA'){
   $dataJson[][]  = array("status" => "success","value" => $fetchValue ,"postcode" => $fetchPostCode,"params"=>""); 

   $notice = $dataJson;
}

我想从PHP获取(参见下文)如何安排我的PHP数组代码

jQuery191013316784294951245_1485527378760([
  {
    "value": "\u003cstrong\u003eNAIROBI\u003c/strong\u003e KENYATTA AVENUE, GENERAL POST OFFICE, 00100",
    "postcode": "00100"
  },
  {
    "value": "\u003cstrong\u003eNAIROBI\u003c/strong\u003e HAILE SALASSIE AVENUE, CITY SQUARE, QLD, 00200",
    "postcode": "00200"
  }
])

1 个答案:

答案 0 :(得分:1)

试试这个:

$dataJson = array("value" => $fetchValue, "postcode" => $fetchPostCode);
$notice = json_encode($dataJson);
echo $notice;

返回包含值的JSON表示的字符串。

http://php.net/manual/en/function.json-encode.php