我无法获得这个json数组的值...我怎么能单独拥有所有这些值!!
{
"id": "jai",
"pwd": "123",
"user": [
{
"fname": "jai",
"lname": "gupta"
},
{
"fname": "sameer",
"lname": "seth"
}
],
"college": "vit"
}
答案 0 :(得分:1)
$myArray = json_decode($json, true);
var_dump($myArray['id']);
var_dump($myArray['user'][0]['fname']);
答案 1 :(得分:0)
您可以通过访问常规的php数组键值对来访问每个“值”。
$jsonn = '{"id":"jai","pwd":"123","user":[{"fname":"jai","lname":"gupta"},{"fname":"sameer","lname":"seth"}],"college":"vit"}';
$new = json_decode($jsonn, true);
$id = $new['id'];
$user = $new['user'];
..... and so on.
希望这有帮助。
干杯!
答案 2 :(得分:0)
您可以将这些值从json解码为object。
$result = json_decode('{"id":"jai","pwd":"123","user":[{"fname":"jai","lname":"gupta"},{"fname":"sameer","lname":"seth"}],"college":"vit"}');
和如下所述:
$result->id;
$result->pwd;