I am receiving this Json:
-{
"events" : -[
0-{
"eventName" : service-review-created,
"version" : 1,
"eventData" : -{
"id" : xxxxxxxx,
"language" : en,
"stars" : 5,
"title" : Friendly sales staff that are genuine,
"text" : Friendly sales staff that are genuine, helpful and most of all NOT pushy and annoying!,
"referenceId" : xxxxxxx,
"createdAt" : 2017-05-07T21:12:00Z,
"link" : https://api.trustpilot.com/v1/reviews/xxxxxxxxxxx,
"consumer" : -{
"id" : xxxxxxxxx,
"name" : Mrs xxxx xxxxx,
"link" : https://api.trustpilot.com/v1/consumers/590f8da00000ff000a9582aa
}
}
}
]
}
I am trying to extract the value "stars".
This is what I'm trying but nothing seems to be working:
$data = json_decode('{"events":[{"eventName":"service-review-created","version":"1","eventData":{"id":"xxxxxxx","language":"en","stars":5,"title":"Friendly sales staff that are genuine","text":"Friendly sales staff that are genuine, helpful and most of all NOT pushy and annoying!","referenceId":"xxxxxx","createdAt":"2017-05-07T21:12:00Z","link":"https://api.trustpilot.com/v1/reviews/590f8da02ecbfc09e8d3045d","consumer":{"id":"590f8da00000ff000a9582aa","name":"Mrs xxxxxxx","link":"https://api.trustpilot.com/v1/consumers/5xxxxxxxx"}}}]}');
$stars = $data->events->eventData->stars;
echo $stars;
Would be delighted if someone could tell me where I'm going wrong.