如何使用PHP解析json?

时间:2017-06-01 09:46:00

标签: php json

{
    "result": "success",
    "clientid": "1",
    "serviceid": null,
    "pid": null,
    "domain": null,
    "totalresults": "2",
    "startnumber": 0,
    "numreturned": 2,
    "products": {
        "product": [
            {
                "id": "1",
                "clientid": "1",
                "orderid": "1",
                "pid": "1",
                "regdate": "2015-01-01",
                "name": "Starter",
                "translated_name": "Starter",
                "groupname": "Shared Hosting",
                "translated_groupname": "Shared Hosting",
                "domain": "demodomain.com",
                "dedicatedip": "",
                "serverid": "1",
                "servername": "Saturn",
                "serverip": "1.2.3.4",
                "serverhostname": "saturn.example.com",
                "suspensionreason": "",
                "firstpaymentamount": "12.95",
                "recurringamount": "12.95",
                "paymentmethod": "authorize",
                "paymentmethodname": "Credit Card",
                "billingcycle": "Monthly",
                "nextduedate": "2016-11-25",
                "status": "Terminated",
                "username": "demodoma",
                "password": "xxxxxxxx",
                "subscriptionid": "",
                "promoid": "0",
                "overideautosuspend": "",
                "overidesuspenduntil": "0000-00-00",
                "ns1": "",
                "ns2": "",
                "assignedips": "",
                "notes": "",
                "diskusage": "0",
                "disklimit": "0",
                "bwusage": "0",
                "bwlimit": "0",
                "lastupdate": "0000-00-00 00:00:00",
                "customfields": {
                    "customfield": []
                },
                "configoptions": {
                    "configoption": []
                }
            },
            {
                "id": "2",
                "clientid": "1",
                "orderid": "2",
                "pid": "3",
                "regdate": "2015-05-20",
                "name": "Plus",
                "translated_name": "Plus",
                "groupname": "Shared Hosting",
                "translated_groupname": "Shared Hosting",
                "domain": "demodomain2.net",
                "dedicatedip": "",
                "serverid": "2",
                "servername": "Pluto",
                "serverip": "2.3.4.5",
                "serverhostname": "pluto.example.com",
                "suspensionreason": "",
                "firstpaymentamount": "24.95",
                "recurringamount": "24.95",
                "paymentmethod": "paypal",
                "paymentmethodname": "PayPal",
                "billingcycle": "Monthly",
                "nextduedate": "2017-01-20",
                "status": "Active",
                "username": "demodom2",
                "password": "xxxxxxxx",
                "subscriptionid": "",
                "promoid": "0",
                "overideautosuspend": "",
                "overidesuspenduntil": "0000-00-00",
                "ns1": "",
                "ns2": "",
                "assignedips": "",
                "notes": "",
                "diskusage": "0",
                "disklimit": "0",
                "bwusage": "0",
                "bwlimit": "0",
                "lastupdate": "0000-00-00 00:00:00",
                "customfields": {
                    "customfield": []
                },
                "configoptions": {
                    "configoption": [
                        {
                            "id": "1",
                            "option": "Sample Config Option",
                            "type": "dropdown",
                            "value": "Selected option value"
                        }
                    ]
                }
            }
        ]
    }
}

How can i parse the product details from json

1 个答案:

答案 0 :(得分:0)

你可以使用php的json decode函数来制作对象,然后从对象中获取数据。

$ data ='在这里写下你的json响应';

$ return = json_decode($ data);

的print_r($返程);

echo $ return-> result;