php - Separate JSON response -
i getting response using unirest library, need separate data, based on data can call next query. here full json response getting while using unirest library
echo '<pre>'; print_r($response->raw_body); echo '</pre>'; { "status": "success", "images": [ "http://www.example.com/12.jpg" ], "photos": [ { "url": "http://www.example.com/12.jpg", "width": 205, "tags": [ { "confidence": 0.978945010372561, "center": { "y": 64, "x": 129 }, "height": 79, "width": 79, "tid": "31337", "attributes": [ { "smile_rating": 0.56, "smiling": true, "confidence": 0.56 } ], "uids": [ { "confidence": 0.35399999999999998, "prediction": "se2", "uid": "se2@sea1" }, { "confidence": 0.28999999999999998, "prediction": "se1", "uid": "se1@sea1" }, { "confidence": 0.16, "prediction": "star1", "uid": "star1@sea1" }, { "confidence": 0.106, "prediction": "se3", "uid": "se3@sea1" }, { "confidence": 0.037999999999999999, "prediction": "se6", "uid": "se6@sea1" }, { "confidence": 0.035000000000000003, "prediction": "se5", "uid": "se5@sea1" }, { "confidence": 0.017999999999999999, "prediction": "se4", "uid": "se4@sea1" } ] } ], "height": 206 } ] } what trying print this
confidence : 0.35399999999999998 similar: test2
well, provided valid json string, use simple json_decode() true flag returns array. example:
$data = json_decode($response->raw_body, true); $i = 0; foreach($data['photos'][0]['tags'][0]['uids'] $value) { if($i == 5) break; echo 'confidence: ' . $value['confidence'] . '<br/>'; echo 'similar: ' . $value['prediction'] . '<br/><br/>'; $i++; }
Comments
Post a Comment