2
I am trying to read a JSON file in php with 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 returning the results in php in 2 formats. The first as follows:
$request = file_get_contents('php://input');
$input = json_decode($request, true);
$id = $input['leads']['nome'];
echo $id;
And the second form 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 anyone help me and tell me where I’m going wrong?! Thanks :D