-3

问题

我想从以下字符串中提取所有值并将其存储在变量中。任何帮助将不胜感激

代码

{"status":0,"body":{"updatetime":1371670079,"more":112,"measuregrps":[{"grpid":126426711,"attrib":2,"date":1371654000,"category":1,"measures":[{"value":8159,"type":1,"unit":-2},{"value":4530,"type":5,"unit":-2},{"value":44478,"type":6,"unit":-3},{"value":3629,"type":8,"unit":-2}]}]}}
4

1 回答 1

2

你试过了json_decode()吗?

如果第二个参数设置为,它将返回一个嵌套数组,true如果省略第二个参数,它将返回嵌套对象。

php> json_decode('{"status":0,"body":{"updatetime":1371670079,"more":112,"measuregrps":[{"grpid":126426711,"attrib":2,"date":1371654000,"category":1,"measures":[{"value":8159,"type":1,"unit":-2},{"value":4530,"type":5,"unit":-2},{"value":44478,"type":6,"unit":-3},{"value":3629,"type":8,"unit":-2}]}]}}', true);
array (
  'status' => 0,
  'body' => 
  array (
    'updatetime' => 1371670079,
    'more' => 112,
    'measuregrps' => 
    array (
      0 => 
      array (
        'grpid' => 126426711,
        'attrib' => 2,
        'date' => 1371654000,
        'category' => 1,
        'measures' => 
        array (
          0 => 
          array (
            'value' => 8159,
            'type' => 1,
            'unit' => -2,
          ),
          1 => 
          array (
            'value' => 4530,
            'type' => 5,
            'unit' => -2,
          ),
          2 => 
          array (
            'value' => 44478,
            'type' => 6,
            'unit' => -3,
          ),
          3 => 
          array (
            'value' => 3629,
            'type' => 8,
            'unit' => -2,
          ),
        ),
      ),
    ),
  ),
)
于 2013-06-19T19:33:24.563 回答