0

i'm using Microsoft Emotion Api and it return a result as a json. so i want to access emotion values and assign that values to php variables. i used json_decode function but it can't do it. result like below

[  
  {
    "faceRectangle": {
      "left": 63,
      "top": 94,
      "width": 66,
      "height": 97
    },
    "scores": {
      "anger": 0.00300731952,
      "contempt": 2.18678448E-08,
      "disgust": 9.284124E-06,
      "fear": 0.0001912825,
      "happiness": 0.9874571,
      "neutral": 0.0009631537,
      "sadness": 1.887755E-05,
      "surprise": 0.008223598
    }
  }
]
Barmar
  • 741,623
  • 53
  • 500
  • 612
Dasun_96
  • 173
  • 1
  • 7

1 Answers1

0

You need to use this if you want it as an array

$array = json_decode($var, true);

Otherwise it will return the json as a object instead of an array

Doing this should let you access it like so:

$fl = $array[0]['faceRectangle']['left'];
Andrew Rayner
  • 1,056
  • 1
  • 6
  • 20