I'm trying to read a JSON file in php in the following format:
{"leads":
[{"id":"1",
"email":"[email protected]",
"user": "[email protected]",
"first_conversion": {
"content": {
"identificador":"ebook-abc",
},
"created_at":"2012-06-04T15:31:35-03:00",
"conversion_origin": {
"source": "source 1",
}
},
"last_conversion": {
"content": {
"identificador":"webinar-abc",
"email_lead":"[email protected]"
},
"created_at":"2012-06-04T15:31:35-03:00",
"cumulative_sum":"2",
},
"custom_fields": {
"Destino": "EUA"
},
"website": "http://www.site.com.br",
"mobile_phone":"48 30252598",
"city":"Sao Paulo",
"state": "SP",
"tags": ["tag 1", "tag 2"],
}]
}
I tried to return the results in php in 2 formats. The first one is as follows:
$request = file_get_contents('php://input');
$input = json_decode($request, true);
$id = $input['leads']['nome'];
echo $id;
And the second way using foreach:
$request = file_get_contents('php://input');
$input = json_decode($request, true);
$lead = $input->leads;
foreach($lead as $result){
echo "ID: ". $result->id;
}
Neither way is returning a result. Can someone help me and tell me where I'm going wrong ?! Thanks: D