READ JSON -

Posted by Giancarlo Alberto Somma on 15-Oct-2019 15:43

HI,

I need to read JSON that does not contain an object name or array.

i.e.

"invoice_info": {

"id": "6376705",
"amount": "1.00",
"invoice_number": "111",
"last_payment_date": "28/05/2018",
"subscriber_no": "111",
"company_no": null,
"query_id": null,
"owner_name_masked": "MU*** MU***",
"foundation_id": 143 

}

I can't see any example in OE 11.7.

Any help is appreciated.

Thx.

All Replies

Posted by Mike Fechner on 15-Oct-2019 15:45

I don't think OpenEdge supports that kind of JSON. You need to add a pair of { } around the string before parsing it.

Posted by Mike Fechner on 15-Oct-2019 15:45

I don't think OpenEdge supports that kind of JSON. You need to add a pair of { } around the string before parsing it.

Posted by Dileep Dasa on 15-Oct-2019 15:54

OpenEdge doesn't support this kind of JSON:

documentation.progress.com/.../index.html

Posted by Jean-Christophe Cardot on 15-Oct-2019 15:56

This is not valid JSON... See https://jsonlint.com/ for example.

Posted by Jean-Christophe Cardot on 15-Oct-2019 15:57

This is not valid JSON... See https://jsonlint.com/ for example.

Posted by Giancarlo Alberto Somma on 15-Oct-2019 17:43

Thanks your reply. I checked JSON is not correct. Below correct, I think, JSON.

{

"count": 1,

"next": null,

"previous": null,

"results": [{

"id": "6376703",

"status": "open",

"amount": "1.00",

"payment_time": null,

"invoice_info": {

"id": "6376705",

"amount": "1.00",

"invoice_number": "111",

"last_payment_date": "28/05/2018",

"subscriber_no": "111",

"company_no": null,

"query_id": null,

"owner_name_masked": "MU*** MU***",

"foundation_id": 143

}

}]

}

My question is for "invoice_info". With this example

def var joObj2 as JsonObject.

i=oJsonArray:LENGTH.

joObj2 = oJsonArray:GetJsonObject(i).

def var charstring as char.

charstring = string(joObj2:GetJsonText("invoice_info")).

message charstring.

charstring contains:

                       "id": "6376705",

"amount": "1.00",

"invoice_number": "111",

"last_payment_date": "28/05/2018",

"subscriber_no": "111",

"company_no": null,

"query_id": null,

"owner_name_masked": "MU*** MU***",

"foundation_id": 143"

How I can READ separately as if it were an array.

Thanks.

G.

Posted by Mike Fechner on 15-Oct-2019 17:50

invoice_info is a JsonObject. You cannot walk it like a JsonArray.
 
To dynamically access the properties of a JsonObject, use the GetNames() property of the JsonObject to receive the property names as an ABL Character Array.

This thread is closed