Доброго времени суток.
Особо не имел дело с json parser на СФ, только xml
Достаю обычные данные вот так:
JSONParser parser = JSON.createParser(jsonStr);
String TokenJson;
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == FindTeg))
{
parser.nextToken();
TokenJson = parser.getText();
}
}
Может лучше посмотреть в сторону Json Serialization and Deserialization? Если структура json постоянная то может стоит ее десериализировать в inner object и работать как с обычным объектом?
{
"Items"
:
[{
"ReportID": "83807275D41A47F889EB",
"ReportOwnerID": "WebAdmin@mackenziefinancial.com",
"ExpenseTypeCode": "AIRFR",
"ExpenseTypeName": "Air",
"SpendCategoryCode": "AIRFR",
"SpendCategoryName": "Airfare",
"PaymentTypeID": "gWpeYjBcS7yOxoeO9CU$s5wJ9RlpKC",
"PaymentTypeName": "Cash",
"TransactionDate": "2015-02-19T00:00:00",
"TransactionCurrencyCode": "CAD",
"TransactionAmount": 123.00000000,
"ExchangeRate": 1.00000000000000,
"PostedAmount": 123.00000000,
"ApprovedAmount": 123.00000000,
"VendorDescription": "234",
"VendorListItemID": null,
"VendorListItemName": null,
"LocationID": "gWuF4OKqoXi8hIi70KwEVK7ksgEl$p1sc3vw",
"LocationName": "Toronto, Ontario",
"LocationSubdivision": "Ontario",
"LocationCountry": "CA",
"Description": "ert",
"IsPersonal": false,
"IsBillable": false,
"IsPersonalCardCharge": false,
"HasImage": false,
"IsImageRequired": true,
"ReceiptReceived": false,
"TaxReceiptType": "R",
"ElectronicReceiptID": null,
"CompanyCardTransactionID": null,
"TripID": null,
"HasItemizations": false,
"AllocationType": "N",
"HasAttendees": false,
"HasVAT": false,
"HasAppliedCashAdvance": false,
"HasComments": false,
"HasExceptions": false,
"IsPaidByExpensePay": false,
"EmployeeBankAccountID": null,
"Journey": null,
"LastModified": "2015-02-19T12:23:33.423",
"FormID": "gWsfxtb$pR0LU8ysQf5ZlvFoA9Hl0BWiqhKg",
"OrgUnit1": {
"Type": "ConnectedList",
"Value": "Distribution",
"Code": "7140",
"ListItemID": "gWrx1fO1OWKtaiIo9NlMUvQmWS$svyDSSGIA"
},
"OrgUnit2": {
"Type": "ConnectedList",
"Value": "Sales Operations",
"Code": "7300",
"ListItemID": "gWrx1fO1OWKFTYf2JkleuofY9DTr7p$pyURg"
},
"OrgUnit3": null,
"OrgUnit4": null,
"OrgUnit5": null,
"OrgUnit6": null,
"Custom1": null,
"Custom2": null,
"Custom3": null,
"Custom4": null,
"Custom5": null,
"Custom6": null,
"Custom7": null,
"Custom8": null,
"Custom9": null,
"Custom10": null,
"Custom11": null,
"Custom12": null,
"Custom13": null,
"Custom14": null,
"Custom15": null,
"Custom16": null,
"Custom17": null,
"Custom18": null,
"Custom19": null,
"Custom20": null,
"Custom21": null,
"Custom22": null,
"Custom23": null,
"Custom24": null,
"Custom25": null,
"Custom26": null,
"Custom27": null,
"Custom28": null,
"Custom29": null,
"Custom30": null,
"Custom31": null,
"Custom32": null,
"Custom33": null,
"Custom34": null,
"Custom35": null,
"Custom36": null,
"Custom37": null,
"Custom38": null,
"Custom39": null,
"Custom40": null,
"ID": "gWvWckcrsgo2vYjzYZhJK93RMdwEDbOAuTA",
"URI": "https://implementation.concursolutions.com/api/v3.0/expense/entries/gWvWckcrsgo2vYjzYZhJK93RMdwEDbOAuTA"
}], "NextPage"
:
null
}Не совсем понимаю как применить. Буду благодарен если подскажете на моем примере.
String jsonStr = '{"Items":[{"ReportID":"83807275D41A47F889EB","ReportOwnerID":"WebAdmin@mackenziefinancial.com","ExpenseTypeCode":"AIRFR","ExpenseTypeName":"Air","SpendCategoryCode":"AIRFR","SpendCategoryName":"Airfare","PaymentTypeID":"gWpeYjBcS7yOxoeO9CU$s5wJ9RlpKC","PaymentTypeName":"Cash","TransactionDate":"2015-02-19T00:00:00","TransactionCurrencyCode":"CAD","TransactionAmount":123.00000000,"ExchangeRate":1.00000000000000,"PostedAmount":123.00000000,"ApprovedAmount":123.00000000,"VendorDescription":"234","VendorListItemID":null,"VendorListItemName":null,"LocationID":"gWuF4OKqoXi8hIi70KwEVK7ksgEl$p1sc3vw","LocationName":"Toronto, Ontario","LocationSubdivision":"Ontario","LocationCountry":"CA","Description":"ert","IsPersonal":false,"IsBillable":false,"IsPersonalCardCharge":false,"HasImage":false,"IsImageRequired":true,"ReceiptReceived":false,"TaxReceiptType":"R","ElectronicReceiptID":null,"CompanyCardTransactionID":null,"TripID":null,"HasItemizations":false,"AllocationType":"N","HasAttendees":false,"HasVAT":false,"HasAppliedCashAdvance":false,"HasComments":false,"HasExceptions":false,"IsPaidByExpensePay":false,"EmployeeBankAccountID":null,"Journey":null,"LastModified":"2015-02-19T12:23:33.423","FormID":"gWsfxtb$pR0LU8ysQf5ZlvFoA9Hl0BWiqhKg","OrgUnit1":{"Type":"ConnectedList","Value":"Distribution","Code":"7140","ListItemID":"gWrx1fO1OWKtaiIo9NlMUvQmWS$svyDSSGIA"},"OrgUnit2":{"Type":"ConnectedList","Value":"Sales Operations","Code":"7300","ListItemID":"gWrx1fO1OWKFTYf2JkleuofY9DTr7p$pyURg"},"OrgUnit3":null,"OrgUnit4":null,"OrgUnit5":null,"OrgUnit6":null,"Custom1":null,"Custom2":null,"Custom3":null,"Custom4":null,"Custom5":null,"Custom6":null,"Custom7":null,"Custom8":null,"Custom9":null,"Custom10":null,"Custom11":null,"Custom12":null,"Custom13":null,"Custom14":null,"Custom15":null,"Custom16":null,"Custom17":null,"Custom18":null,"Custom19":null,"Custom20":null,"Custom21":null,"Custom22":null,"Custom23":null,"Custom24":null,"Custom25":null,"Custom26":null,"Custom27":null,"Custom28":null,"Custom29":null,"Custom30":null,"Custom31":null,"Custom32":null,"Custom33":null,"Custom34":null,"Custom35":null,"Custom36":null,"Custom37":null,"Custom38":null,"Custom39":null,"Custom40":null,"ID":"gWvWckcrsgo2vYjzYZhJK93RMdwEDbOAuTA","URI":"https://implementation.concursolutions.com/api/v3.0/expense/entries/gWvWckcrsgo2vYjzYZhJK93RMdwEDbOAuTA"}],"NextPage":null}';Map<String, Object> mapJsonObjects = (Map<String, Object>) JSON.deserializeUntyped(jsonStr);
List<Object> items = (List<Object>)mapJsonObjects.get('Items');
for(Object item : items){
Map<String, Object> itemMap = (Map<String, Object>)item;
Map<String, Object> OrgUnit1 = (Map<String, Object>)itemMap.get('OrgUnit1');
object code = OrgUnit1.get('Code');
System.debug('OrgUnit1.code: ' + code);
}
однако баг на форуме нашёлся :o
Это не баг, это фича :)))))))))))))))))))))))
Починю :)))))))))
hotfix http://prntscr.com/69mwxi :)
Помогите плиз. Мозг так уже забит, вообще не вкуриваю ничвото(
я же всё сделал, что не понятно?
О! Я ж говорю что глючит меня уже) Сорри. Дедлайн тут на одном проекте, мозг спалил уже. Спасибо!!