您可以在以下位置进行验证
网址:http://jsonlint.com/
您必须使用 php "json_decode()" 函数来解码 json 编码数据。
基本上 json_decode() 函数将 JSON 数据转换为 PHP 数组。
语法:json_decode(data, dataTypeBoolean, depth, options)
data : - 你想在 PHP 中解码的 json 数据。
dataTypeBoolean(Optional) :- 布尔值,如果设置为“true”,则使函数返回 PHP 关联数组,如果省略此参数或将其设置为“false”,则返回 PHP stdClass 对象”。这两种数据类型都可以像数组一样访问,并使用基于数组的 PHP 循环进行解析。
depth :- 可选的递归限制。使用整数作为此参数的值。
选项:- 可选 JSON_BIGINT_AS_STRING 参数。
现在进入您的代码
$json_string = '{"a":1,"b":2,"c":3,"d":4,"e":5}' ;
将有效的 json 数据分配给单引号 ('') 内的变量 $json_string
json 字符串已经有双引号。
// here i am decoding a json string by using a php 'json_decode' function, as mentioned above & passing a true parameter to get a PHP associative array otherwise it will bydefault return a PHP std class objecy array.
$json_decoded_data = json_decode($json_string, true);
// just can check here your encoded array data.
// echo '<pre>';
// print_r($json_decoded_data);
// loop to extract data from an array
foreach ($json_decoded_data as $key => $value) {
echo "$key | $value <br/>";
}