dongwei6457 2013-04-12 19:18
浏览 48
已采纳

使用PHP从JSON响应访问数组值

I am new to JSON and I am having a problem accessing particular values in the JSON array that is being returned from the API call. For instance, I would like to access the name value in the response data below (these are the first two responses from the API call). I know I am missing something obvious but I can't quit get it. Any help would be appreciated:

ReadResponse::__set_state(array(
   0 => 
  array (
    'address' => '6866 N Rochester Rd',
    'category' => 'Food & Beverage > Restaurants',
    'category_ids' => 
    array (
      0 => 347,
    ),
    'category_labels' => 
    array (
      0 => 
      array (
        0 => 'Social',
        1 => 'Food and Dining',
        2 => 'Restaurants',
      ),
    ),
    'country' => 'us',
    'factual_id' => '8e6aacfa-b435-407d-83f9-90cec16c1cf8',
    'latitude' => 42.69804075,
    'locality' => 'Rochester Hills',
    'longitude' => -83.134586375,
    'name' => 'Sushi Little Tokyo',
    'neighborhood' => 
    array (
      0 => '\\Livernois-Tienken\\',
    ),
    'postcode' => '48306',
    'region' => 'MI',
    'status' => '1',
    'tel' => '(248) 608-1260',
  ),
   1 => 
  array (
    'address' => '2964 S Rochester Rd',
    'category' => 'Food & Beverage > Restaurants',
    'category_ids' => 
    array (
      0 => 347,
    ),
    'category_labels' => 
    array (
      0 => 
      array (
        0 => 'Social',
        1 => 'Food and Dining',
        2 => 'Restaurants',
      ),
    ),
    'country' => 'us',
    'factual_id' => '35d2fc06-a941-4dbf-9dcb-204964fec730',
    'latitude' => 42.636786765426,
    'locality' => 'Rochester Hills',
    'longitude' => -83.131888674506,
    'name' => 'Pudthi and Sushi',
    'postcode' => '48307',
    'region' => 'MI',
    'status' => '1',
    'tel' => '(248) 299-6890',
    'website' => 'http://www.pudthaiandsushi.com',
  ),
  • 写回答

2条回答 默认 最新

  • douji8033 2013-04-13 09:39
    关注

    Try this PHP function json_decode() to translate your JSON response into a PHP multidimensional array where you can easily access the values in the array like the name would be

    $name = $myPHPArray->country->name; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效