AnsweredAssumed Answered

Turn JSON object into records

Question asked by jcpython on Jan 29, 2019
Latest reply on Jan 29, 2019 by jcpython


Hey everyone,

 

I'm just so baffled on how to parse JSON that is formatted like this:

 

{

"base" : "THB",

"date" : "2019-01-29",

"rates" :

{

"AUD" : 0.0443277486,

"BGN" : 0.0543413631,

"BRL" : 0.1187380178,

"CAD" : 0.042071629,

"CHF" : 0.0315412186,

"CNY" : 0.213739546,

"CZK" : 0.7153732878,

"DKK" : 0.2074129644,

"EUR" : 0.027784724,

"GBP" : 0.0240990803,

"HKD" : 0.2490066961,

"HRK" : 0.2062543414,

"HUF" : 8.813592287,

"IDR" : 447.1562335028,

"ILS" : 0.1167236254,

"INR" : 2.2590647662,

"ISK" : 3.8009502376,

"JPY" : 3.4739240366,

"KRW" : 35.489983607,

"MXN" : 0.6033536162,

"MYR" : 0.130396488,

"NOK" : 0.2696090689,

"NZD" : 0.0463838182,

"PHP" : 1.6656108472,

"PLN" : 0.1194076297,

"RON" : 0.1321497041,

"RUB" : 2.1029896363,

"SEK" : 0.2875941208,

"SGD" : 0.0429107277,

"THB" : 1,

"TRY" : 0.1685560279,

"USD" : 0.0317357117,

"ZAR" : 0.4322191659

}

}

 

I have a table called ExchangeRates with a textfield called "Currencycode" and a number field called "Rate"  and all i want to do loop through the above JSON result and create a record for the first object value and put AUD in CurrencyCode field and put 0.0443277486 in the Rate field then add new record and continue down the list.

 

 

I've tried numerous things however everyone i look the JSON others use in examples are using a much different looking format ( im not very educated in JSON but know a little and have worked with it many times before. i have tried the following:

 

JSONGetElement ( EXCHANGERATES::API_Source; "rates[1]")

 

OR

 

JSONGetElement ( EXCHANGERATES::API_Source; "rates.[1]")

 

and I get a result like this:

? in Json::Value::operator[](ArrayIndex)const: requires arrayValue

Outcomes