我正在寻找一种方法来访问此JSON文件数据。我感兴趣的是提取名为documentjsonblob
的属性,如下所示。
object(Quadrem\Model\Order)[201]
protected '_dateCreated' => null
protected '_buyerCode' => null
array (size=2)
2415 =>
array (size=23)
'@storeid' => string '813' (length=3)
'@active' => string '1' (length=1)
'@created' => string '2013-11-25 12:28:21' (length=19)
'documentjsonblob' => string '{"HEAD":{"ORDERSEQUENCE":"0","TOTAL_TAX":7.9,"TOTAL_AMOUNT":86.9,"NUMBER":"AKMon3","TYPE":"NB","TYPE_NAME":"Standard PO","SUPPLIER":"0000002122","CREATED":"2013-04-29T12:00:00Z","CONTRACT_NUMBER":"","EXTERNAL_REFERENCE":"","CONTACT_PERSON":"Caroline Howlett","COMMENT":[""],"CURRENCY":"AUD","DELIVERY_TERMS":"DeliveryCondition|","PAYMENT_TERMS":[{"TEXT1":"21st day of next month after receipt"}],"NET_VALUE":79.0,"DELIVERY_ADDRESS":{"NAME_1":"KGTP FACILITY","NAME_2":"GAS TREATMENT PLANT","NAME_3":"KGPF","POSTAL_CODE":"6714","CITY":"Karratha","STREET":"Withnell Bay","REGION":"AUWA","REGION_NAME":"AUWA","COUNTRY":"AU"}]}' (length=3029)
'documenttype' => string 'PO' (length=2)
1890 =>
array (size=23)
'@storeid' => null
'@active' => null
我不太确定哪种编码的JSON文件是这样的。如果有人可以提供帮助,我将不胜感激。
感谢。
答案 0 :(得分:0)
由于您在评论中提到它是var_dump
的输出而您想获得documentjsonblob
,所以请按照以下步骤操作:
object(Quadrem\Model\Order)[201]
,这意味着您var_dumped 对象,比如$my_obj
array (size=2)
表示您有一个数组,您需要的是位于数组的第一个元素中,因此$my_obj[0]
$my_obj[0]
包含一个关联数组,所需的索引为documentjsonblob
,因此我们可以将 String 表示形式设为:
$my_arr = $my_obj[0];
$json_str = $my_arr['documentjsonblob'];
现在$json_str
保存String表示,将其转换为PHP对象:
$json_obj = json_decode($json_str);
所以现在$json_obj
拥有你想要的对象。