How to convert json string to json object in php
代言
代言 2017-06-30 09:56:25
0
2
931

Seeking
Similar to js

msg = eval('(' msg ')');

How to write

Currently we know that php uses json_decode() for string json and returns null, and Baidu has no other methods

代言
代言

reply all(2)
曾经蜡笔没有小新
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

var_dump(json_decode($json));
var_dump(json_decode($json, true));

?>

The results are

object(stdClass)#1 (5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}

array(5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}

If you return null after json_decode, have you written the string like this"{ 'bar': 'baz' }", this can be parsed into JSON normally in JS, but it must be written as ' in PHP { "bar": "baz" }', attributes and values ​​must be in double quotes

世界只因有你

Use json_decode(), the premise is that the json format attributes and values ​​must use double quotes. If you use python, you don’t need to use double quotes

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template