Json 3 维数组到 PHP
Json 3 dimensional array to PHP
我正在使用 Microsoft Emotion Api,结果 return json。所以我想访问情感值并将该值分配给 php 变量。我使用了 json_decode 功能,但它不能这样做。
结果如下
[
{
"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
}
}
]
如果你想要它作为一个数组,你需要使用它
$array = json_decode($var, true);
否则它将return json 作为对象而不是数组
这样做应该能让您像这样访问它:
$fl = $array[0]['faceRectangle']['left'];
我正在使用 Microsoft Emotion Api,结果 return json。所以我想访问情感值并将该值分配给 php 变量。我使用了 json_decode 功能,但它不能这样做。 结果如下
[
{
"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
}
}
]
如果你想要它作为一个数组,你需要使用它
$array = json_decode($var, true);
否则它将return json 作为对象而不是数组
这样做应该能让您像这样访问它:
$fl = $array[0]['faceRectangle']['left'];