[英]how to convert a json_encoded data to an associative array in php?
我有这个数据。如何将其转换为php关联数组呢?实际上我很困惑。我尝试了json_decode并反序列化 。这里有人可以帮助我。
"data": {
"address": "101, B Wing, Ashapura Park, Dombivli East",
"area": "thane",
"area_id": 51466,
"field_agent": {
"email": "abin@example.in",
"name": "Jacob Mattom",
"phone": 2147483647
},
"geo_location_city": "thane",
"geo_location_city_id": 2430,
"keywords": [
"sample for tesing"
],
"lat": null,
"lng": null,
"location_id": 5578,
"media": [
{
"MediaId": "0bd41ec2f0bc11e58fd5066a28c33ece",
"thumb_url": "http://example-datapipeline-staging.s3-ap-southeast-1.examplezz.com/0bd41ec2f0bc11e58fd5066a28c33ece.mp4",
},
{
"MediaId": "28c3823ef0bc11e5b825066a28c33ece",
"thumb_url": "http://example-datapipeline-staging.s3-ap-southeast-1.examplezz.com/28c3823ef0bc11e5b825066a28c33ece.mp4",
}
],
"meta": {
"Product": [
{
"brand": "",
"categorykeywords": [
"Construction Tools Indl",
"Construction Tools",
"Industrial Construction Tools",
"Tools",
""
],
"categorykeywordsexact": [
"Construction Tools Indl",
"Construction Tools",
"Industrial Construction Tools",
"Tools",
""
],
"categorypath": "Top/Construction Equipments/Construction Tools- Indl",
"description": "",
"id": 10395376,
"imageurls": "",
"intattribute": [
{
"answer": 0,
"qaggr": "",
"question": ""
},
{
"answer": 0,
"qaggr": "",
"question": ""
},
{
"answer": 0,
"qaggr": "",
"question": ""
},
{
"answer": 0,
"qaggr": "",
"question": ""
}
],
"keywords": [],
"l1category": "Building & Construction",
"l2category": "Construction Equipments",
"name": "",
"parkedkeywords": [],
"stringattribute": [
{
"aaggr": [
"New"
],
"answer": [
"New"
],
"qaggr": "Condition",
"question": "Condition"
},
{
"aaggr": [
"Customized",
"Warranty"
],
"answer": [
"Customized",
"Warranty"
],
"qaggr": "Services",
"question": "Services"
},
{
"aaggr": [
"Electric",
"Hydraulic",
"Pneumatic"
],
"answer": [
"Electric",
"Hydraulic",
"Pneumatic"
],
"qaggr": "Technology",
"question": "Technology"
},
{
"aaggr": [
"Cutting Tools",
"Hand Tools",
"Plumbing Tools",
"Power Tools"
],
"answer": [
"Cutting Tools",
"Hand Tools",
"Plumbing Tools",
"Power Tools"
],
"qaggr": "Tools",
"question": "Tools"
}
]
}
],
"keywords1": [
"sample for tesing"
],
"project": "ace"
},
"outlet_status": "Valid Data",
"outlet_type": 0,
"phones": [
{
"type": "mobile",
"value": "+9198955548554"
},
{
"type": "tollfree",
"value": ""
}
],
"pincode": "22601",
"pincode_id": 151522,
"products": null,
"progress": "field executive assigned",
"qc_agency": null,
"qc_agent": null
},
"message": null,
"status": true
}
我有这个数据。如何将其转换为php关联数组呢?实际上我很困惑。我尝试了json_decode并反序列化 。这里有人可以帮助我。
我相信最简单的解决方案是使用json_decode。
$json= '"data": {"address": "101, B Wing, Ashapura Park, Dombivli East", "area": "thane", "area_id": 51466, "field_agent": {"email": "abin@example.in", "name": "Jacob Mattom", "phone": 2147483647 }}';
$obj = json_decode($json);
echo $obj->address;
echo $obj->field_agent->email;
您的JSON数据结构错误。 因此,PHP的json_decode无法使用。 首先修复它。 要解决此问题,您可以使用在线json编辑器。 您的json数据出了什么问题:
现在可以使用json_decode了。
这是JSON数据的固定版本: http : //www.jsoneditoronline.org/?id=689de1b78324faaced8018a2ccda1845
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.