Answer the question
In order to leave comments, you need to log in
How to parse multidimensional json php?
I'm trying to parse this json:
{
"ok": true,
"result": [
{
"message": {
"date": 1270110569,
"text": "hello",
"from": {
"first_name": "Test",
"last_name": "FGHTZX",
"is_bot": false,
"id": 234512896,
"language_code": "ru"
},
"message_id": 16,
"chat": {
"first_name": "Test",
"last_name": "FGHTZX",
"type": "private",
"id": 234512896
}
},
"update_id": 474148724
}
]
}
$string = file_get_contents($json_file);
$result_parse = json_decode($string, TRUE);
$r=$result_parse->result->message->text;
print "$r";
$r=$result_parse['result'];
print "$r";
Answer the question
In order to leave comments, you need to log in
"result": [
means that the array will go now. those. result in this case is an array "message": {
means that the object will go now. those. message in this case is an object.
In your case
$string = file_get_contents($json_file);
$result_parse = json_decode($string, TRUE);
$r=$result_parse->result[0]->message->text;
print "$r";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question