-
慕码人8056858
它是一个 JSON 字符串而不是 PHP 数组。要转换,您可以这样做: $string = '{ "Type": "ACCREC", "Contact": { "ContactID": "37918a06-92f6-4edb-bfe0-1fc041c90f8b", "Name": "Boom FM", "ContactPersons": [], "Addresses": [], "Phones": [], "ContactGroups": [], "HasAttachments": false, "HasValidationErrors": false }, "LineItems": [], "Date": "2020-04-08", "DueDate": "2020-04-21", "LineAmountTypes": "Exclusive", "InvoiceNumber": "INV-0010", "Reference": "Training", "CurrencyCode": "USD", "Status": "PAID", "SubTotal": 500, "TotalTax": 41.25, "Total": 541.25, "InvoiceID": "4c4db294-3633-45cd-8706-f0b3b0079609", "HasAttachments": false, "IsDiscounted": false, "Payments": [], "Prepayments": [], "Overpayments": [], "AmountDue": 0, "AmountPaid": 0, "FullyPaidOnDate": "2020-04-19", "AmountCredited": 541.25, "UpdatedDateUTC": "2008-12-20T18:38:32+01:00", "CreditNotes": [ { "Date": "2020-04-19", "LineItems": [], "Total": 541.25, "CreditNoteID": "602f5486-664e-492f-b4d1-e12df1d4b8ba", "CreditNoteNumber": "CN-0014", "AppliedAmount": 541.25, "HasAttachments": false, "HasErrors": false } ], "HasErrors": false }' $data = json_decode($string, true); //Second parameter forces conversion to array var_dump($data);
-
扬帆大鱼
好吧,我会因为我的回答而被钉牢,因为我真的把它混为一谈,但它有效:$result = "Xero 会计 API 的数组输出"; $json = ""; foreach ($result as $results) { $json = $json . $results; } $obj = json_decode($json); $Type = $obj->{'Type'};
-
qq_遁去的一_1
You can deal with this JSON string in PHP as follows://声明一个json字符串$json = '{ "Type": "ACCREC", "Contact": { "ContactID": "37918a06-92f6-4edb-bfe0-1fc041c90f8b", "Name": "Boom FM", "ContactPersons": [], "Addresses": [], "Phones": [], "ContactGroups": [], "HasAttachments": false, "HasValidationErrors": false }, "LineItems": [], "Date": "2020-04-08", "DueDate": "2020-04-21", "LineAmountTypes": "Exclusive", "InvoiceNumber": "INV-0010", "Reference": "Training", "CurrencyCode": "USD", "Status": "PAID", "SubTotal": 500, "TotalTax": 41.25, "Total": 541.25, "InvoiceID": "4c4db294-3633-45cd-8706-f0b3b0079609", "HasAttachments": false, "IsDiscounted": false, "Payments": [], "Prepayments": [], "Overpayments": [], "AmountDue": 0, "AmountPaid": 0, "FullyPaidOnDate": "2020-04-19", "AmountCredited": 541.25, "UpdatedDateUTC": "2008-12-20T18:38:32+01:00", "CreditNotes": [ { "Date": "2020-04-19", "LineItems": [], "Total": 541.25, "CreditNoteID": "602f5486-664e-492f-b4d1-e12df1d4b8ba", "CreditNoteNumber": "CN-0014", "AppliedAmount": 541.25, "HasAttachments": false, "HasErrors": false } ], "HasErrors": false }'; //1st Way: // Use json_decode() function to $obj= json_decode($json);$item = $obj->{'Type'};print $item;//2nd way:$obj= json_decode($json,true);$item = $obj['Type'];print $item;