0

I am looking to remove strings and colon symbols prior to an object so that I can search the object for its entities.

For example, I have:

{ "result": [ { "face_id": "b668c61ad349ea928c75ba46338008af", "landmark": { "contour_chin": { "x": 55.448237, "y": 35.152167 }, "contour_left1": { "x": 40.641011, "y": 26.241833 }, "contour_left2": { "x": 40.791324, "y": 27.7615 }

and I would like to have:

{55.448237, 35.15216},{40.641011,26.241833 },{40.791324,27.7615 }

If there's no easy way to remove the strings, can you recommend an easy way to search for the corresponding number. So.. I search for "contour_left2" and get {40.791324,27.7615 } returned.

Thank you.

aynber
  • 22,380
  • 8
  • 50
  • 63
clutch1020
  • 31
  • 1
  • 7
  • 2
    What you have is a json string, use `json_decode($jsonString)` to convert it into an array or an array of objects. – JimL Dec 15 '16 at 20:13
  • Possible duplicate of [Parsing JSON file with PHP](http://stackoverflow.com/questions/4343596/parsing-json-file-with-php) – radoh Dec 15 '16 at 22:08

1 Answers1

1

So as it was suggested by @JimL you are dealing with a json string. If you decode it:

$data = @json_decode($string);

Then $data will be an object, and you will be able to access it's properties:

$contour_left2 = $data->result[0]->landmark->contour_left2;
// $contour_left2->x, $contour_left2->y

(Of course you should do some checking first to make sure $data->result is not empty, etc...)

I'm not sure if you absolutely need the coordinates as a simple tuple, but you could then build a small array:

$tuple = array($contour_left2->x, $contour_left2->y);

Hope this helps!

nibnut
  • 3,072
  • 2
  • 15
  • 17