Compose a JSON member as a string?
Posted: Wed Aug 21, 2024 5:38 am
I need to go through JSON records and, in each case, find a particular member and then extract that (and all its subs) as a string. I can find it easily enough, but extracting it is another matter. Is there any easy way to do this?
Code: Select all
c34.s = Chr(34)
jsonString.s = "{"+c34+"blob"+c34+":{"+c34+"mimeType"+c34+":"+c34+"image/jpeg"+c34+","+c34+"$type"+c34+":"+c34+"blob"+c34+","+c34+"size"+c34+":11689,"+c34+"ref"+c34+":{"+c34+"$link"+c34+":"+c34+"bafkreih44nkqvldurfdvtnctr3m7a3wmn7ayv2vku3oyhdslzdj3pidarm"+c34+"}}}"
j = ParseJSON(#PB_Any,jsonString)
If j
ObjectValue = JSONValue(j)
If ExamineJSONMembers(ObjectValue)
While NextJSONMember(ObjectValue)
Select JSONMemberKey(ObjectValue)
Case "blob"
value = JSONMemberValue(ObjectValue)
If ExamineJSONMembers(value)
While NextJSONMember(value)
If JSONMemberKey(value) = "ref"
value2 = JSONMemberValue(value)
t.s = ComposeJSON(value2)
Break 2
EndIf
Wend
EndIf
EndSelect
Wend
EndIf
FreeJSON(j)
EndIf