0
您好我知道我可以參考JSON變量使用此下列方式在PHP解碼後:引用變量下手@從JSON在PHP
$data = json_decode(file_get_contents("php://input"));
$myfile = fopen("aaaa.txt", "w") or die("Unable to open file!");
fwrite($myfile, $data->form->variable);
fclose($myfile);
然而,有一個變量,@在開始JSON。 我該如何引用該變量? $data->form->@name
不起作用,$data->form['@name']
也不起作用。
這裏是我的JSON文件:(我想在@name)
{
"build_id": "d776ccf19c994f65b8605ecc0711d94b",
"archived": false,
"uiversion": "1",
"attachments": {},
"form": {
"@uiVersion": "1",
"@xmlns": "http://openrosa.org/formdesigner/77618A3E-48A4-474D-9AC5-80D7BFA952F7",
"@name": "External Good Receiving Note",
"Truck_num": "f",
"invoice_num": "fd",
"#type": "data",
"driver_signature": "",
"arrival_time": "2017-05-22T19:31:00.000000Z",
"driver_name": "f",
"meta": {
"@xmlns": "http://openrosa.org/jr/xforms",
"app_build_version": 118,
"commcare_version": "2.35.3",
"instanceID": "8e895f2c-30c6-4ba9-979c-e99af9f4ad1c",
"username": "wang",
"userID": "306dd277c96773330613bfa78005a596",
"appVersion": "CommCare Android, version \"2.35.3\"(431724). App v118. CommCare Version 2.35. Build 431724, built on: 2017-04-19",
"timeEnd": "2017-05-22T19:31:48.042000Z",
"timeStart": "2017-05-22T19:31:26.109000Z",
"geo_point": null,
"deviceID": "352331080741542"
},
"officer": "ff",
"Signature": "",
"waybill_num": "f",
"warehouse_code": "ff",
"@version": "118",
"PO": "15",
"comment": "ff",
"name": {
"@xmlns": "grn"
}
},
"initial_processing_complete": true,
"received_on": "2017-05-22T19:31:48.170284Z",
"app_id": "0d24ecddaf46a8516780a7ab32b1d120",
"is_phone_submission": "2.0",
"version": "118",
"domain": "crs-emergency-response-system",
"problem": null,
"resource_uri": "",
"type": "data",
"id": "8e895f2c-30c6-4ba9-979c-e99af9f4ad1c",
"metadata": {
"app_build_version": 118,
"doc_type": "Metadata",
"commcare_version": "2.35.3",
"instanceID": "8e895f2c-30c6-4ba9-979c-e99af9f4ad1c",
"deprecatedID": null,
"username": "wang",
"userID": "306dd277c96773330613bfa78005a596",
"appVersion": "CommCare Android, version \"2.35.3\"(431724). App v118. CommCare Version 2.35. Build 431724, built on: 2017-04-19",
"timeEnd": "2017-05-22T19:31:48.042000",
"timeStart": "2017-05-22T19:31:26.109000",
"geo_point": null,
"deviceID": "352331080741542",
"location": null
}
}
json_decode後的文件,它仍然有那些變量之前@符號:
stdClass Object
(
[app_id] => 0d24ecddaf46a8516780a7ab32b1d120
[archived] =>
[attachments] => stdClass Object
(
)
[build_id] => d776ccf19c994f65b8605ecc0711d94b
[domain] => crs-emergency-response-system
[form] => stdClass Object
(
[#type] => data
[@name] => External Good Receiving Note
[@uiVersion] => 1
[@version] => 118
[@xmlns] => http://openrosa.org/formdesigner/77618A3E-48A4-474D-9AC5-80D7BFA952F7
[PO] => 15
[Signature] =>
[Truck_num] => f
[arrival_time] => 2017-05-22T19:31:00.000000Z
[comment] => ff
[driver_name] => f
[driver_signature] =>
[invoice_num] => fd
[meta] => stdClass Object
(
[@xmlns] => http://openrosa.org/jr/xforms
[appVersion] => CommCare Android, version "2.35.3"(431724). App v118. CommCare Version 2.35. Build 431724, built on: 2017-04-19
[app_build_version] => 118
[commcare_version] => 2.35.3
[deviceID] => 352331080741542
[geo_point] =>
[instanceID] => 8e895f2c-30c6-4ba9-979c-e99af9f4ad1c
[timeEnd] => 2017-05-22T19:31:48.042000Z
[timeStart] => 2017-05-22T19:31:26.109000Z
[userID] => 306dd277c96773330613bfa78005a596
[username] => wang
)
[name] => stdClass Object
(
[@xmlns] => grn
)
[officer] => ff
[warehouse_code] => ff
[waybill_num] => f
)
[id] => 8e895f2c-30c6-4ba9-979c-e99af9f4ad1c
[initial_processing_complete] => 1
[is_phone_submission] => 2.0
[metadata] => stdClass Object
(
[appVersion] => CommCare Android, version "2.35.3"(431724). App v118. CommCare Version 2.35. Build 431724, built on: 2017-04-19
[app_build_version] => 118
[commcare_version] => 2.35.3
[deprecatedID] =>
[deviceID] => 352331080741542
[doc_type] => Metadata
[geo_point] =>
[instanceID] => 8e895f2c-30c6-4ba9-979c-e99af9f4ad1c
[location] =>
[timeEnd] => 2017-05-22T19:31:48.042000
[timeStart] => 2017-05-22T19:31:26.109000
[userID] => 306dd277c96773330613bfa78005a596
[username] => wang
)
[problem] =>
[received_on] => 2017-05-22T19:31:48.170284Z
[resource_uri] =>
[type] => data
[uiversion] => 1
[version] => 118
)
向我們展示您的JSON示例,我從來沒有聽說過帶有@鍵或任何特殊字符的鍵的任何json ... – matiaslauriti
您能否請您展示您的json? –
編輯,粘貼json文件在這裏@ AlivetoDie – weeo