Hi all
I am investigating the use of Chilkat's tools for parsing JSON objects but I am having trouble developing a generic routine. For example, take the following:
Local loJsonObject As 'Chilkat_9_5_0.JsonObject' Local lcStrJsonObject, lnNumPets lcStrJsonObject = '{"pets":[{"name":"jack","breed":"terrier"},{"name":"john","breed":"bulldog"},{"name":"joe","breed":"terrier"}]}' loJsonObject = CreateObject('Chilkat_9_5_0.JsonObject') loJsonObject.Load(lcStrJsonObject) i = 0 lnNumPets = loJsonObject.SizeOfArray("pets") DO WHILE i < lnNumPets loJsonObject.I = i ? STR(i) + ": " + loJsonObject.StringOf("pets[i].name") + "," + loJsonObject.StringOf("pets[i].breed") i = i + 1 ENDDO
What I am trying to do is make the code generic such that I do not need to refer to "pets", "name" and "breed". Any help would be much appreciated. I have found a generic method for parsing JSON arrays but so far have been unable to do so for JSON objects
Paul Newton
Hi Paul,
This might be what you are looking for: https://www.example-code.com/foxpro/json_paths.asp
I think the outside one you'll need to know. But there might be a way to deal with it.
Each time I've used the JsonObject, I've known the structure I was expecting. So doing something generic wasn't needed. I just needed to step through layers and these made it easier.
HTH, Tracy
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Paul Newton Sent: Tuesday, February 12, 2019 9:49 AM To: profoxtech@leafe.com Subject: Parsing a JSON object
Hi all
I am investigating the use of Chilkat's tools for parsing JSON objects but I am having trouble developing a generic routine. For example, take the following:
Local loJsonObject As 'Chilkat_9_5_0.JsonObject' Local lcStrJsonObject, lnNumPets lcStrJsonObject = '{"pets":[{"name":"jack","breed":"terrier"},{"name":"john","breed":"bulldog" },{"name":"joe","breed":"terrier"}]}' loJsonObject = CreateObject('Chilkat_9_5_0.JsonObject') loJsonObject.Load(lcStrJsonObject) i = 0 lnNumPets = loJsonObject.SizeOfArray("pets") DO WHILE i < lnNumPets loJsonObject.I = i ? STR(i) + ": " + loJsonObject.StringOf("pets[i].name") + "," + loJsonObject.StringOf("pets[i].breed") i = i + 1 ENDDO
What I am trying to do is make the code generic such that I do not need to refer to "pets", "name" and "breed". Any help would be much appreciated. I have found a generic method for parsing JSON arrays but so far have been unable to do so for JSON objects
Paul Newton
[excessive quoting removed by server]
Thanks Tracy - I'll take a look
-----Original Message----- From: ProfoxTech profoxtech-bounces@leafe.com On Behalf Of Tracy Pearson Sent: 12 February 2019 15:22 To: profoxtech@leafe.com Subject: RE: Parsing a JSON object
Sent by an external sender ------------------------------
Hi Paul,
This might be what you are looking for: https://www.example-code.com/foxpro/json_paths.asp
I think the outside one you'll need to know. But there might be a way to deal with it.
Each time I've used the JsonObject, I've known the structure I was expecting. So doing something generic wasn't needed. I just needed to step through layers and these made it easier.
HTH, Tracy
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Paul Newton Sent: Tuesday, February 12, 2019 9:49 AM To: profoxtech@leafe.com Subject: Parsing a JSON object
Hi all
I am investigating the use of Chilkat's tools for parsing JSON objects but I am having trouble developing a generic routine. For example, take the following:
Local loJsonObject As 'Chilkat_9_5_0.JsonObject' Local lcStrJsonObject, lnNumPets lcStrJsonObject = '{"pets":[{"name":"jack","breed":"terrier"},{"name":"john","breed":"bulldog" },{"name":"joe","breed":"terrier"}]}' loJsonObject = CreateObject('Chilkat_9_5_0.JsonObject') loJsonObject.Load(lcStrJsonObject) i = 0 lnNumPets = loJsonObject.SizeOfArray("pets") DO WHILE i < lnNumPets loJsonObject.I = i ? STR(i) + ": " + loJsonObject.StringOf("pets[i].name") + "," + loJsonObject.StringOf("pets[i].breed") i = i + 1 ENDDO
What I am trying to do is make the code generic such that I do not need to refer to "pets", "name" and "breed". Any help would be much appreciated. I have found a generic method for parsing JSON arrays but so far have been unable to do so for JSON objects
Paul Newton
[excessive quoting removed by server]