【发布时间】:2018-02-27 23:31:15
【问题描述】:
如何将此 json 字符串转换为数组?我试过json_decode,但它返回null。
它以前是一个 .json 文件,我使用 file_get_contents 获取它的数据。
我也尝试过使用 foreach 循环,但 PHP 库应该可以提供答案。
我还从 stackoverflow 中查看了另一个相关主题,但没有成功。
谢谢!
{
"1":{
"entity_id":"1",
"type_id":"simple",
"sku":"dress_test",
"status":"1",
"visibility":"4",
"tax_class_id":"2",
"weight":"1.0000",
"price":"1500.0000",
"special_price":"1000.0000",
"name":"Wedding dress",
"url_key":"dress",
"country_of_manufacture":"AO",
"msrp_display_actual_price_type":"2",
"gift_message_available":"1",
"news_from_date":"2012-03-21 00:00:00",
"news_to_date":"2012-03-24 00:00:00",
"special_from_date":"2012-03-21 00:00:00",
"special_to_date":"2012-03-24 00:00:00",
"description":"White wedding dress"
},
"2":{
"entity_id":"2",
"type_id":"simple",
"sku":"blazers",
"status":"1",
"visibility":"4",
"tax_class_id":"2",
"weight":"1.0000",
"price":"200.0000",
"special_price":"100.0000",
"name":"Brazes",
"url_key":"brazes",
"country_of_manufacture":"AO",
"msrp_display_actual_price_type":"2",
"gift_message_available":"1",
"news_from_date":"2012-03-21 00:00:00",
"news_to_date":"2012-03-24 00:00:00",
"special_from_date":"2012-03-21 00:00:00",
"special_to_date":"2012-03-24 00:00:00",
"description":"Blue brazes"
},
"3":{
"entity_id":"3",
"type_id":"simple",
"sku":"black_sunglasses",
"status":"1",
"visibility":"4",
"tax_class_id":"2",
"weight":"0.2000",
"price":"500.0000",
"special_price":"300.0000",
"name":"Sunglasses",
"url_key":"sunglasses",
"country_of_manufacture":"AR",
"msrp_display_actual_price_type":"2",
"gift_message_available":null,
"news_from_date":null,
"news_to_date":null,
"special_from_date":"2012-03-21 00:00:00",
"special_to_date":"2012-03-24 00:00:00",
"description":"Black sunglasses"
},
"4":{
"entity_id":"4",
"type_id":"simple",
"sku":"jacket",
"status":"1",
"visibility":"4",
"tax_class_id":"2",
"weight":"1.0000",
"price":"800.0000",
"name":"Jacket",
"url_key":"jacket",
"country_of_manufacture":"AO",
"msrp_display_actual_price_type":"2",
"gift_message_available":"1",
"news_from_date":"2012-03-21 00:00:00",
"news_to_date":"2012-03-24 00:00:00",
"special_from_date":"2012-03-21 00:00:00",
"special_to_date":"2012-03-24 00:00:00",
"description":"Black jacket"
},
"5":{
"entity_id":"5",
"type_id":"simple",
"sku":"green_shirts",
"status":"0",
"visibility":"4",
"tax_class_id":"2",
"weight":"1.0000",
"price":"800.0000",
"name":"Green shirts",
"url_key":"green_shirts",
"country_of_manufacture":"AO",
"msrp_display_actual_price_type":"2",
"gift_message_available":"1",
"news_from_date":"2012-03-21 00:00:00",
"news_to_date":"2012-03-24 00:00:00",
"special_from_date":"2012-03-21 00:00:00",
"special_to_date":"2012-03-24 00:00:00",
"description":"Green shirts"
},"6":{
"entity_id":"6",
"type_id":"simple",
"sku":"orange_shirts",
"status":"1",
"visibility":"4",
"tax_class_id":"2",
"weight":"1.0000",
"price":"800.0000",
"name":"Orange shirts",
"url_key":"orange",
"country_of_manufacture":"AO",
"msrp_display_actual_price_type":"2",
"gift_message_available":"1",
"news_from_date":"2012-03-21 00:00:00",
"news_to_date":"2012-03-24 00:00:00",
"special_from_date":"2012-03-21 00:00:00",
"special_to_date":"2012-03-24 00:00:00",
"description":"Orange shirts",
}
}
【问题讨论】:
-
你试过了吗:json_decode($jsondata, true)?
-
如果您能提供Minimal, Complete, and Verifiable example,那就太好了。