0

I have searched and read a lot of different forums to manage JSON data i have tried many things, but none of them works ;(

{"data": {"results": [{"qid_data": {"custom_id": "XXXXXX", "labels": "YYYYY", "meta": "{}", "bbox": [73, 57, 128, 516], "obj_id": "ZZZZZZ"}, "qid": "WWWWWWWW"}], "error": 0}}

I would like to get the values of: custom_id, labels, bbox, objet_id, qid

Right now I have the following code (for example for custom_id)

$json_output = json_decode($data);
foreach ($json_output as $json_result) {
echo "custom_id:".$json_result->data->results->qid_data->custom_id;
}

I have tried all the variations possible.

$json_result->results->qid_data->custom_id;

OR

$json_result->results->qid_data->custom_id;

OR

$json_result->data->results->custom_id;

OR

$json_result->results->custom_id;

I never get the result, always an error

If someone can help on how to export with an example for data custom_id, bbox, qid

4

1 回答 1

3
{"data": {"results": [{"qid_data": {"

不等于

$json_result->results->qid_data

它等于

 $json_output->data->results[0]->qid_data

注意显示结果的方括号是一个列表

{"data": {"results": [{"qid_data": {"
                     ^

看起来您想要的是迭代该列表

foreach ($json_output->data->results as $result) {
    echo "custom_id:".$result->qid_data->custom_id;
}
于 2013-01-20T13:33:06.013 回答