如何将此JSON转换为php数组,以及如何仅获取特定值 [英] How to convert this JSON to php array and also how to get specific values only

查看:49
本文介绍了如何将此JSON转换为php数组,以及如何仅获取特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只希望对此JSON进行审核.

I want to have only review from this JSON.

var json = {
  "provider": {
    "id": "1982660171",
    "display_name": "Stephen R Guy, MD",
    "last_name": "Guy",
    "first_name": "Stephen",
    "middle_name": "Russell",
    "master_name": "Stephen_Guy",
    "degree_types": "MD",
    "familiar_name": "Stephen",
    "years_experience": "27",
    "birth_year": "1956",
    "birth_month": "5",
    "birth_day": "23",
    "gender": "M",
    "is_limited": "false",
    "url_deep": "http:\/\/www.vitals.com\/doctor\/profile\/1982660171\/Stephen_Guy",
    "url_public": "http:\/\/www.vitals.com\/doctors\/Dr_Stephen_Guy.html",
    "status_code": "A",
    "client_ids": "1",
    "quality_indicator_set": [{
      "type": "quality-indicator\/consumer-feedback",
      "count": "2",
      "suboverall_set": [{
        "name_short": "Promptness",
        "overall": "3"
      }, {
        "name_short": "Courteous Staff",
        "overall": "4"
      }, {
        "name_short": "Bedside Manner",
        "overall": "4"
      }, {
        "name_short": "Spends Time with Me",
        "overall": "4"
      }, {
        "name_short": "Follow Up",
        "overall": "4"
      }],
      "name": "Consumer Reviews",
      "overall": "4.0",
      "measure_set": [{
        "feedback_response_id": "1756185",
        "input_source_ids": "{0}",
        "date": "1301544000",
        "value": "4",
        "scale": {
          "best": "1",
          "worst": "4"
        },
        "review": {
          "type": "review\/consumer",
          "comment": "I will never birth with another dr.  Granted that's not saying much as I don't like dr's but I actually find him as valuable as the midwives who I adore.  I liked Horlacher but when Kitty left I followed the midwives and then followed again....Dr. Guy is GREAT.  I honestly don't know who I'd rather support me at my birth; Margie and Lisa or Dr. Guy.  ....I wonder if I can just get all of them.Guy's great.  Know what you want.  Tell him.  Be strong and he'll support you.I give him 10 stars.  Oh...my baby's 3 years old now.  He's GREAT! ",
          "date": "1301544000"
        },
        "sub_measure": [{
          "name": "Waiting time during a visit",
          "name_short": "Promptness",
          "value": "3",
          "scale": {
            "best": "4",
            "worst": "1"
          }
        }, {
          "name": "Courtesy and professionalism of office staff ",
          "name_short": "Courteous Staff",
          "value": "4",
          "scale": {
            "best": "4",
            "worst": "1"
          }
        }, {
          "name": "Bedside manner (caring)",
          "name_short": "Bedside Manner",
          "value": "4",
          "scale": {
            "best": "4",
            "worst": "1"
          }
        }, {
          "name": "Spending enough time with me",
          "name_short": "Spends Time with Me",
          "value": "4",
          "scale": {
            "best": "4",
            "worst": "1"
          }
        }, {
          "name": "Following up as needed after my visit",
          "name_short": "Follow Up",
          "value": "4",
          "scale": {
            "best": "4",
            "worst": "1"
          }
        }]
      }, {
        "feedback_response_id": "420734",
        "input_source_ids": "{76}",
        "link": "http:\/\/local.yahoo.com\/info-15826842-guy-stephen-r-md-university-women-s-health-center-dayton",
        "date": "1142398800",
        "value": "4",
        "scale": {
          "best": "1",
          "worst": "4"
        },
        "review": {
          "type": "review\/consumer",
          "comment": "Excellent Doctor: I really like going to this office. They are truely down to earth people and talk my \"non-medical\" language. I have been using thier office since 1997 and they have seen me through 2 premature pregnancies!",
          "date": "1142398800"
        }
      }],
      "wait_time": "50"
    }]
  }
};

推荐答案

<?php
//Note I changed the json a bit to make it parsable

$json = '{ "provider":{ "id":"1982660171", "display_name":"Stephen R Guy, MD", "last_name":"Guy", "first_name":"Stephen", "middle_name":"Russell", "master_name":"Stephen_Guy", "degree_types":"MD", "familiar_name":"Stephen", "years_experience":"27", "birth_year":"1956", "birth_month":"5", "birth_day":"23", "gender":"M", "is_limited":"false", "url_deep":"http:\\/\\/www.vitals.com\\/doctor\\/profile\\/1982660171\\/Stephen_Guy", "url_public":"http:\\/\\/www.vitals.com\\/doctors\\/Dr_Stephen_Guy.html", "status_code":"A", "client_ids":"1", "quality_indicator_set":[ { "type":"quality-indicator\\/consumer-feedback", "count":"2", "suboverall_set":[ { "name_short":"Promptness", "overall":"3" }, { "name_short":"Courteous Staff", "overall":"4" }, { "name_short":"Bedside Manner", "overall":"4" }, { "name_short":"Spends Time with Me", "overall":"4" }, { "name_short":"Follow Up", "overall":"4" } ], "name":"Consumer Reviews", "overall":"4.0", "measure_set":[ { "feedback_response_id":"1756185", "input_source_ids":"{0}", "date":"1301544000", "value":"4", "scale":{ "best":"1", "worst":"4" }, "review":{ "type":"review\\/consumer", "comment":"I will never birth with another dr. Granted that\'s not saying much as I don\'t like dr\'s but I actually find him as valuable as the midwives who I adore. I liked Horlacher but when Kitty left I followed the midwives and then followed again....Dr. Guy is GREAT. I honestly don\'t know who I\'d rather support me at my birth; Margie and Lisa or Dr. Guy. ....I wonder if I can just get all of them.Guy\'s great. Know what you want. Tell him. Be strong and he\'ll support you.I give him 10 stars. Oh...my baby\'s 3 years old now. He\'s GREAT! ", "date":"1301544000" }, "sub_measure":[ { "name":"Waiting time during a visit", "name_short":"Promptness", "value":"3", "scale":{ "best":"4", "worst":"1" } }, { "name":"Courtesy and professionalism of office staff ", "name_short":"Courteous Staff", "value":"4", "scale":{ "best":"4", "worst":"1" } }, { "name":"Bedside manner (caring)", "name_short":"Bedside Manner", "value":"4", "scale":{ "best":"4", "worst":"1" } }, { "name":"Spending enough time with me", "name_short":"Spends Time with Me", "value":"4", "scale":{ "best":"4", "worst":"1" } }, { "name":"Following up as needed after my visit", "name_short":"Follow Up", "value":"4", "scale":{ "best":"4", "worst":"1" } } ] }, { "feedback_response_id":"420734", "input_source_ids":"{76}", "link":"http:\\/\\/local.yahoo.com\\/info-15826842-guy-stephen-r-md-university-women-s-health-center-dayton", "date":"1142398800", "value":"4", "scale":{ "best":"1", "worst":"4" }, "review":{ "type":"review\\/consumer", "comment":"Excellent Doctor: I really like going to this office. They are truely down to earth people and talk my \\"non-medical\\" language. I have been using thier office since 1997 and they have seen me through 2 premature pregnancies!", "date":"1142398800" } } ], "wait_time":"50" } ] } } ';

$obj = json_decode($json);

//This is how you can retrieve data 
print $obj->{'provider'}->{'id'};
?>

这篇关于如何将此JSON转换为php数组,以及如何仅获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆