JSON Parsing Problem

I have spent more time than I’m will to admit trying to parse this JSON string. I get the two values but have not figured out how to cycle through the Readings. I have been working with the built in Xojo classes, JSONMBS and Kem’s JSONItem_MTC. The last two seem easier to work with as they don’t require everything to be converted to text (I will have some binary data to work with later that will be sent using EncodeBase64 and don’t know what converting that to text will do so I would prefer not to bother with it.)

{ "FacilityID":54321, "FacCode":"12345", "Readings":[ { "MeterNo":"1", "When":"2019-02-26 11:27:54", "Reading":"1765" }, { "MeterNo":"2", "When":"2019-02-26 11:28:19", "Reading":"962" }, { "MeterNo":"3", "When":"2019-02-26 11:30:26", "Reading":"2100" } ] }

The Readings object is an array, so you would use the array methods of JSONItem. I lean toward the classic JSONItem because it’s not namespaced and has no data conversion requirements. I’m told there’s issues and that’s why JSONItem_MTC exists, but I haven’t had problems yet.

[code]dim jsBase as new JSONItem(sThatJSON)
dim jsReadings as JSONItem = jsBase.Lookup(“Readings”, nil)

if jsReadings = nil then
// Handle the error
return

end

if jsReadings.IsArray = false then
// Handle error, the JSON has changed since
return

end

dim iMax as Integer = jsReadings.Count - 1
for i as Integer = 0 to iMax
dim jsThis as JSONItem = jsReadings.Value(i)

// jsThis is an object with the MeterNo, When, and Reading values here

next
[/code]

Or you can have a look at https://www.dropbox.com/s/33sh379y0rwqnif/Dean.xojo_binary_project?dl=1 which uses the new but deprecated framework.

Two outstanding solutions. Wayne, your reply is way more than expected, but wonderful. Thank you. I’ll be using portions of both solutions in my app.