[JSON] How to remove object

Just starting out? Need help? Post your questions and find answers here.
Paradox
User
User
Posts: 23
Joined: Tue Dec 09, 2014 7:16 pm
Location: Brasil

[JSON] How to remove object

Post by Paradox »

I'm testing RemoveJSONElement and RemoveJSONMember not work for my, what remove "lineup" object?

Code: Select all

Define json_text$ = "[{"+Chr(34)+"example"+Chr(34)+":"+Chr(34)+"1"+Chr(34)+","+Chr(34)+"lineup"+Chr(34)+":{"+Chr(34)+"element"+Chr(34)+":"+Chr(34)+"element1"+Chr(34)+"}}]"
ParseJSON(0, json_text$)
If IsJSON(0)
;   RemoveJSONElement(JSONValue(0),1)
;   RemoveJSONMember(JSONValue(0),"lineup")
    Debug ComposeJSON(0)
EndIf
infratec
Always Here
Always Here
Posts: 6818
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [JSON] How to remove object

Post by infratec »

Hi,

Code: Select all

Define json_text$ = "[{"+Chr(34)+"example"+Chr(34)+":"+Chr(34)+"1"+Chr(34)+","+Chr(34)+"lineup"+Chr(34)+":{"+Chr(34)+"element"+Chr(34)+":"+Chr(34)+"element1"+Chr(34)+"}}]"
ParseJSON(0, json_text$)
If IsJSON(0)
  Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
  ;RemoveJSONElement(JSONValue(0), 0)
  RemoveJSONMember(GetJSONElement(JSONValue(0), 0), "lineup")
  Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
EndIf
you have a json list arround [], so you need to select the element of the list.
Post Reply