Hi,
I am trying to read data records returned from a web service in json format. It contains a complex structure and starts as an array. Please find bellow a sample text.
I need to read all records and from each record find some values.
ls_Error = lnv_package.LoadString(ls_html) does not work, it returns
"Failed to load the JSON data because its root node is not an object"
I am using:
ls_Error = lnv_JsonParser.LoadString(ls_html)
if Len(ls_Error) > 0 then
MessageBox("Error", ls_Error)
end if
ll_RootObject = lnv_JsonParser.GetRootItem()
ll_ChildCount = lnv_JsonParser.GetChildCount(ll_RootObject)
// Obtains the values of child items
for ll_Index = 1 to ll_ChildCount
ls_key = lnv_JsonParser.GetChildKey(ll_RootObject, ll_Index)
next
The child count is correct, but ls_key is always ""
I need the first field "uuid" and then find some others.
Any ideas?
REgards
Alfredo Santibáñez
DATA SAMPLE
[{"uuid":"8e9cca46-21a2-11ea-a945-0242c0a8b008","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/businessthirdparties/8e9cca46-21a2-11ea-a945-0242c0a8b008"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/businessthirdparties/8e9cca46-21a2-11ea-a945-0242c0a8b008/versions/1"}],"identificationCounter":1,"legalName":"Julio Avel Valqui Gomez","commercialName":"Julio Avel Valqui Gomez","acronym":"PE-20006945","addresses":[],"commercialIds":[],"taxIds":[],"internationalStandardCertifications":[],"productCertifications":[],"complianceRating":{"uuid":"8e9cf158-21a2-11ea-a945-0242c0a8b008","mdmVersion":1,"dateOfRating":"2019-01-01","complianceRatingTypeMD":{"uuid":"67fe80c1-edc9-42b0-818e-12d07268dba7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/compliance/complianceratingtypes/67fe80c1-edc9-42b0-818e-12d07268dba7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/compliance/complianceratingtypes/67fe80c1-edc9-42b0-818e-12d07268dba7/versions/0"}],"code":"APPROVED","description":"Approved"}},"priceFixationTerms":[],"businessThirdPartyReferenceIds":[],"legalCountryMD":{"uuid":"bcdf1600-7a27-11e8-b8b2-0242ac120006","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006/versions/1"}],"name":"PERU","unLocode":"PE","countryCode":"PE","functions":[]},"businessTypeMD":{"uuid":"a66316f7-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/organisationtypes/a66316f7-9ef4-11e7-be27-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/organisationtypes/a66316f7-9ef4-11e7-be27-00ff0b1c94f7/versions/0"}],"code":"SP","description":"Sole Proprietorship","category":"Sole Proprietorship","businessThirdPartyMandatory":{"uuid":"a66316f7-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"checkOwner":false,"checkUltimateBeneficiaryOwner":false,"checkRepresentative":false,"checkContactPerson":false}},"ownersMD":[{"uuid":"2182a1aa-20e5-11ea-a945-0242c0a8b008","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/individuals/2182a1aa-20e5-11ea-a945-0242c0a8b008"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/individuals/2182a1aa-20e5-11ea-a945-0242c0a8b008/versions/1"}],"firstName":"Julio Avel","lastName":"Valqui Gomez","identificationCounter":1,"addressingForm":"Mr","personalIdNumber":"PE-20006945","contacts":[],"citizenshipMD":{"uuid":"bcdf1600-7a27-11e8-b8b2-0242ac120006","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006/versions/1"}],"name":"PERU","unLocode":"PE","countryCode":"PE","functions":[]},"identificationTypeMD":{"uuid":"a775143d-db0f-4533-b965-239e58ae43d3","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/identificationtypes/a775143d-db0f-4533-b965-239e58ae43d3"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/identificationtypes/a775143d-db0f-4533-b965-239e58ae43d3/versions/0"}],"code":"IC","description":"Identification Card"}}],"thirdPartyTypesMD":[{"uuid":"4f1d0521-9ef4-11e7-b90a-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/thirdpartytypes/4f1d0521-9ef4-11e7-b90a-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/thirdpartytypes/4f1d0521-9ef4-11e7-b90a-00ff0b1c94f7/versions/0"}],"code":"CS-P","description":"Coffee Supplier – Producer","category":"Coffee Supplier"}],"presentationOfDocumentsMD":{"uuid":"a667d204-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/presentationofdocuments/a667d204-9ef4-11e7-be27-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/presentationofdocuments/a667d204-9ef4-11e7-be27-00ff0b1c94f7/versions/0"}],"code":"BANK","description":"Via Bank"},"paymentTermMD":{"uuid":"a6789b4a-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/paymentterms/a6789b4a-9ef4-11e7-be27-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/paymentterms/a6789b4a-9ef4-11e7-be27-00ff0b1c94f7/versions/0"}],"code":"CAD","description":"Cash Against presentation of documents","viaBank":false}},{"uuid":"a8bfec86-21a2-11ea-a945-0242c0a8b008","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/businessthirdparties/a8bfec86-21a2-11ea-a945-0242c0a8b008"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/businessthirdparties/a8bfec86-21a2-11ea-a945-0242c0a8b008/versions/1"}],"identificationCounter":2,"legalName":"Julio Avel Valqui Gomez","commercialName":"Julio Avel Valqui Gomez","acronym":"PE-20006945","addresses":[],"commercialIds":[],"taxIds":[],"internationalStandardCertifications":[],"productCertifications":[],"complianceRating":{"uuid":"a8c01398-21a2-11ea-a945-0242c0a8b008","mdmVersion":1,"dateOfRating":"2019-01-01","complianceRatingTypeMD":{"uuid":"67fe80c1-edc9-42b0-818e-12d07268dba7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/compliance/complianceratingtypes/67fe80c1-edc9-42b0-818e-12d07268dba7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/compliance/complianceratingtypes/67fe80c1-edc9-42b0-818e-12d07268dba7/versions/0"}],"code":"APPROVED","description":"Approved"}},"priceFixationTerms":[],"businessThirdPartyReferenceIds":[],"legalCountryMD":{"uuid":"bcdf1600-7a27-11e8-b8b2-0242ac120006","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006/versions/1"}],"name":"PERU","unLocode":"PE","countryCode":"PE","functions":[]},"businessTypeMD":{"uuid":"a66316f7-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/organisationtypes/a66316f7-9ef4-11e7-be27-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/organisationtypes/a66316f7-9ef4-11e7-be27-00ff0b1c94f7/versions/0"}],"code":"SP","description":"Sole Proprietorship","category":"Sole Proprietorship","businessThirdPartyMandatory":{"uuid":"a66316f7-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"checkOwner":false,"checkUltimateBeneficiaryOwner":false,"checkRepresentative":false,"checkContactPerson":false}},"ownersMD":[{"uuid":"282fc3ea-20e5-11ea-a945-0242c0a8b008","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/individuals/282fc3ea-20e5-11ea-a945-0242c0a8b008"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/individuals/282fc3ea-20e5-11ea-a945-0242c0a8b008/versions/1"}],"firstName":"Julio Avel","lastName":"Valqui Gomez","identificationCounter":2,"addressingForm":"Mr","personalIdNumber":"PE-20007921","contacts":[],"citizenshipMD":{"uuid":"bcdf1600-7a27-11e8-b8b2-0242ac120006","mdmVersion":1,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/locations/bcdf1600-7a27-11e8-b8b2-0242ac120006/versions/1"}],"name":"PERU","unLocode":"PE","countryCode":"PE","functions":[]},"identificationTypeMD":{"uuid":"a775143d-db0f-4533-b965-239e58ae43d3","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/identificationtypes/a775143d-db0f-4533-b965-239e58ae43d3"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/foundation/identificationtypes/a775143d-db0f-4533-b965-239e58ae43d3/versions/0"}],"code":"IC","description":"Identification Card"}}],"thirdPartyTypesMD":[{"uuid":"4f1d0521-9ef4-11e7-b90a-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/thirdpartytypes/4f1d0521-9ef4-11e7-b90a-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/thirdpartytypes/4f1d0521-9ef4-11e7-b90a-00ff0b1c94f7/versions/0"}],"code":"CS-P","description":"Coffee Supplier – Producer","category":"Coffee Supplier"}],"presentationOfDocumentsMD":{"uuid":"a667d204-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/presentationofdocuments/a667d204-9ef4-11e7-be27-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/businesspartner/presentationofdocuments/a667d204-9ef4-11e7-be27-00ff0b1c94f7/versions/0"}],"code":"BANK","description":"Via Bank"},"paymentTermMD":{"uuid":"a6789b4a-9ef4-11e7-be27-00ff0b1c94f7","mdmVersion":0,"links":[{"rel":"self","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/paymentterms/a6789b4a-9ef4-11e7-be27-00ff0b1c94f7"},{"rel":"self immutable","href":"https://sbox.edwh.nkg.net/mdm/rest/trade/paymentterms/a6789b4a-9ef4-11e7-be27-00ff0b1c94f7/versions/0"}],"code":"CAD","description":"Cash Against presentation of documents","viaBank":false}}]
I do have the next comment, the json I have to read is different, please find bellow an adaptation to what I received from your example, with two records in the main array.
1) I have initially an array
2) I need to read "file_name" from both records as it is the unique key of the data
3) this field "file_name" is not a node, is just one more record in the structure
4) in my case, many nodes will contain a record with file_name attribute. I don't need them, but probably will need name and price
How would you apply the object in this scenario?
[
{
"file_name": "example.json",
"number": "5",
"articles": [
{
"name": "watch",
"price": 208.3,
"stock": true,
"file_name":"x.json"
},
{
"name": "phone",
"price": 108.55,
"stock": false,
"file_name":"json2.txt"
}
]
}
{
"file_name": "example2.json",
"number": "52",
"articles": [
{
"name": "watch2",
"price": 208.3,
"stock": true
},
{
"name": "phone2",
"price": 108.55,
"stock": false
}
]
}
]
Best Regards
Alfredo