PHP converts this string into an array. this post is edited by tangl198710 at 12:11:55.
The string is as follows:
{'Aid ': '21', 'ctl _ a_cpu': 'df ', 'ctl _ a_ram': 'df ', 'ctl _ a_disk': 'df ', 'ctl _ a_fip': 'df ', 'ctl _ a_ OS': 'c _ 1_2 ', 'ctl _ a_ OS _lang': 'c _ 4_1, c_4_3 ', 'Comment ': 'other requirements \ ', \ 'Haha \', \ '', 'total': '000000', 'typeid': '6 '}
How can I convert such a string into an array?
Convert the above string to an array: What is the value after the subscript before the number?
Reply to discussion (solution)
$ Str = <
Does json_decode pay special attention to using this function? I printed it blank and found other solutions. But I want to know how to use the json_decode function.
Your format is incorrect.
I don't know what tool you use to output json data.
Let's take a look at this example.
$ Str1 = '{"a": 21 }';
$ Str2 = "{\" B \ ": 21 }";
$ Str3 = "{'C': 21 }";
Print_r (json_decode ($ str1, true ));
Print_r (json_decode ($ str2, true ));
Print_r (json_decode ($ str3, true ));
The output result is Array ([a] => 21) Array ([B] => 21)
The third print_r output is blank.
Json_decode (string $ json [, bool $ assoc])
Accept a JSON string and convert it to a PHP variable
Parameters
Json
A string in json string format.
Assoc
If this parameter is set to TRUE, array instead of object is returned.
Same as above, directly use the json_decode string.
Write as follows:
Json_decode ($ str, true );
Note that if "true" is not added, the object is converted into an array.
Well .. As a result, json_decode () cannot be directly used for processing. the manual conversion method is changed:
$ Str = <
'; Print_r ($ result );
PHP array basics
Http://3aj.cn/php/39.html