我試圖運行解碼陣列上一個foreach,具體如下:foreach所JSON是雖然沒有工作的var_dump正顯示出陣列
陣:
[
{
"addresses": [
{
"city": "Hod Hash",
"country": "Israel",
"countryCode": "",
"localizedLabel": "work",
"originalLabel": "_$!<Work>!$_",
"state": "",
"street": "Shahaf6\nSec",
"zip": 41343
}
],
"birthday": "2006-12-2712: 00: 00+0000",
"creationDate": "2016-12-2711: 30: 00+0000",
"emails": [
{
"address": "[email protected]",
"localizedLabel": "Lab",
"originalLabel": "Lab"
},
{
"address": "[email protected]",
"localizedLabel": "iCloud",
"originalLabel": "iCloud"
}
],
"job": {
"company": "Layer",
"jobTitle": ""
},
"modificationDate": "2016-12-2711: 30: 00+0000",
"name": {
"compositeName": "Test Contant",
"firstName": "Test",
"lastName": "Contant",
"middleName": ""
},
"notes": "Guy yd he hcgd g\n",
"phones": [
{
"localizedLabel": "home",
"number": "054-8862488",
"originalLabel": "_$!<Home>!$_"
},
{
"localizedLabel": "iPhone",
"number": "054-7532635",
"originalLabel": "iPhone"
},
{
"localizedLabel": "work",
"number": "03-4214532",
"originalLabel": "_$!<Work>!$_"
}
],
"recordId": "908",
"source": {
"sourceID": 0,
"sourceType": ""
},
"websites": [
"www.layer.com",
"google.com"
]
},
{
"addresses": [
{
"city": "Hod Hash",
"country": "Israel",
"countryCode": "",
"localizedLabel": "work",
"originalLabel": "_$!<Work>!$_",
"state": "",
"street": "Shahaf6\nSec",
"zip": 41343
}
],
"birthday": "2006-12-2712: 00: 00+0000",
"creationDate": "2016-12-2711: 30: 00+0000",
"emails": [
{
"address": "[email protected]",
"localizedLabel": "Lab",
"originalLabel": "Lab"
},
{
"address": "[email protected]",
"localizedLabel": "iCloud",
"originalLabel": "iCloud"
}
],
"job": {
"company": "Layer",
"jobTitle": ""
},
"modificationDate": "2016-12-2711: 30: 00+0000",
"name": {
"compositeName": "Test Contant",
"firstName": "Test",
"lastName": "Contant",
"middleName": ""
},
"notes": "Guy yd he hcgd g\n",
"phones": [
{
"localizedLabel": "home",
"number": "054-8862488",
"originalLabel": "_$!<Home>!$_"
},
{
"localizedLabel": "iPhone",
"number": "054-7532635",
"originalLabel": "iPhone"
},
{
"localizedLabel": "work",
"number": "03-4214532",
"originalLabel": "_$!<Work>!$_"
}
],
"recordId": "908",
"source": {
"sourceID": 0,
"sourceType": ""
},
"websites": [
"www.layer.com",
"google.com"
]
},
{
"addresses": [
{
"city": "Hod Hash",
"country": "Israel",
"countryCode": "",
"localizedLabel": "work",
"originalLabel": "_$!<Work>!$_",
"state": "",
"street": "Shahaf6\nSec",
"zip": 41343
}
],
"birthday": "2006-12-2712: 00: 00+0000",
"creationDate": "2016-12-2711: 30: 00+0000",
"emails": [
{
"address": "[email protected]",
"localizedLabel": "Lab",
"originalLabel": "Lab"
},
{
"address": "[email protected]",
"localizedLabel": "iCloud",
"originalLabel": "iCloud"
}
],
"job": {
"company": "Layer",
"jobTitle": ""
},
"modificationDate": "2016-12-2711: 30: 00+0000",
"name": {
"compositeName": "Test Contant",
"firstName": "Test",
"lastName": "Contant",
"middleName": ""
},
"notes": "Guy yd he hcgd g\n",
"phones": [
{
"localizedLabel": "home",
"number": "054-8862488",
"originalLabel": "_$!<Home>!$_"
},
{
"localizedLabel": "iPhone",
"number": "054-7532635",
"originalLabel": "iPhone"
},
{
"localizedLabel": "work",
"number": "03-4214532",
"originalLabel": "_$!<Work>!$_"
}
],
"recordId": "908",
"source": {
"sourceID": 0,
"sourceType": ""
},
"websites": [
"www.layer.com",
"google.com"
]
},
{
"addresses": [
{
"city": "Hod Hash",
"country": "Israel",
"countryCode": "",
"localizedLabel": "work",
"originalLabel": "_$!<Work>!$_",
"state": "",
"street": "Shahaf6\nSec",
"zip": 41343
}
],
"birthday": "2006-12-2712: 00: 00+0000",
"creationDate": "2016-12-2711: 30: 00+0000",
"emails": [
{
"address": "[email protected]",
"localizedLabel": "Lab",
"originalLabel": "Lab"
},
{
"address": "[email protected]",
"localizedLabel": "iCloud",
"originalLabel": "iCloud"
}
],
"job": {
"company": "Layer",
"jobTitle": ""
},
"modificationDate": "2016-12-2711: 30: 00+0000",
"name": {
"compositeName": "Test Contant",
"firstName": "Test",
"lastName": "Contant",
"middleName": ""
},
"notes": "Guy yd he hcgd g\n",
"phones": [
{
"localizedLabel": "home",
"number": "054-8862488",
"originalLabel": "_$!<Home>!$_"
},
{
"localizedLabel": "iPhone",
"number": "054-7532635",
"originalLabel": "iPhone"
},
{
"localizedLabel": "work",
"number": "03-4214532",
"originalLabel": "_$!<Work>!$_"
}
],
"recordId": "908",
"source": {
"sourceID": 0,
"sourceType": ""
},
"websites": [
"www.layer.com",
"google.com"
]
},
{
"addresses": [
{
"city": "Hod Hash",
"country": "Israel",
"countryCode": "",
"localizedLabel": "work",
"originalLabel": "_$!<Work>!$_",
"state": "",
"street": "Shahaf6\nSec",
"zip": 41343
}
],
"birthday": "2006-12-2712: 00: 00+0000",
"creationDate": "2016-12-2711: 30: 00+0000",
"emails": [
{
"address": "[email protected]",
"localizedLabel": "Lab",
"originalLabel": "Lab"
},
{
"address": "[email protected]",
"localizedLabel": "iCloud",
"originalLabel": "iCloud"
}
],
"job": {
"company": "Layer",
"jobTitle": ""
},
"modificationDate": "2016-12-2711: 30: 00+0000",
"name": {
"compositeName": "Test Contant",
"firstName": "Test",
"lastName": "Contant",
"middleName": ""
},
"notes": "Guy yd he hcgd g\n",
"phones": [
{
"localizedLabel": "home",
"number": "054-8862488",
"originalLabel": "_$!<Home>!$_"
},
{
"localizedLabel": "iPhone",
"number": "054-7532635",
"originalLabel": "iPhone"
},
{
"localizedLabel": "work",
"number": "03-4214532",
"originalLabel": "_$!<Work>!$_"
}
],
"recordId": "908",
"source": {
"sourceID": 0,
"sourceType": ""
},
"websites": [
"www.layer.com",
"google.com"
]
},
{
"addresses": [
{
"city": "Hod Hash",
"country": "Israel",
"countryCode": "",
"localizedLabel": "work",
"originalLabel": "_$!<Work>!$_",
"state": "",
"street": "Shahaf6\nSec",
"zip": 41343
}
],
"birthday": "2006-12-2712: 00: 00+0000",
"creationDate": "2016-12-2711: 30: 00+0000",
"emails": [
{
"address": "[email protected]",
"localizedLabel": "Lab",
"originalLabel": "Lab"
},
{
"address": "[email protected]",
"localizedLabel": "iCloud",
"originalLabel": "iCloud"
}
],
"job": {
"company": "Layer",
"jobTitle": ""
},
"modificationDate": "2016-12-2711: 30: 00+0000",
"name": {
"compositeName": "Test Contant",
"firstName": "Test",
"lastName": "Contant",
"middleName": ""
},
"notes": "Guy yd he hcgd g\n",
"phones": [
{
"localizedLabel": "home",
"number": "054-8862488",
"originalLabel": "_$!<Home>!$_"
},
{
"localizedLabel": "iPhone",
"number": "054-7532635",
"originalLabel": "iPhone"
},
{
"localizedLabel": "work",
"number": "03-4214532",
"originalLabel": "_$!<Work>!$_"
}
],
"recordId": "908",
"source": {
"sourceID": 0,
"sourceType": ""
},
"websites": [
"www.layer.com",
"google.com"
]
}
]
陣列處於變量$inputData
。
則:
$decodedContact = json_decode($inputData['contact']); //disregard contact as it's coming from the body as key: contact and value: array`
當我運行:
foreach ($decodedContact as $contact){
echo $contact.'<br>';
}
我得到:
Object of class stdClass could not be converted to string
當我var_dump($decodedData);
這一切看起來很棒...:\
您是否嘗試過使用的var_dump($接觸 - >地址); ? – sAcH