RosettaCodeData/Task/JSON/PureBasic/json.purebasic

35 lines
1.3 KiB
Plaintext

OpenConsole()
If CreateJSON(1)
PB_Team_Members=SetJSONObject(JSONValue(1))
SetJSONString(AddJSONMember(PB_Team_Members,"PB_Team_Member_1"),"Frederic Laboureur")
SetJSONString(AddJSONMember(PB_Team_Members,"PB_Team_Member_2"),"Andre Beer")
SetJSONString(AddJSONMember(PB_Team_Members,"PB_Team_Member_3"),"Timo Harter")
EndIf
If CreateJSON(2)
Former_Team_Members=SetJSONArray(JSONValue(2))
SetJSONString(AddJSONElement(Former_Team_Members),"Richard Andersson")
SetJSONString(AddJSONElement(Former_Team_Members),"Benny Sels")
SetJSONString(AddJSONElement(Former_Team_Members),"Danilo Krahn")
EndIf
PrintN("PureBasic - Team Members:")
PrintN(ComposeJSON(1,#PB_JSON_PrettyPrint)+#CRLF$)
PrintN("PureBasic - Former Team Members:")
PrintN(ComposeJSON(2,#PB_JSON_PrettyPrint)+#CRLF$)
#DL=Chr(34)
PB_Special_thanks$="[ " +#DL+"Gary Willoughby"+#DL+", " +#DL+"Mark James"+#DL+", " +#DL+"Neil Hodgson"+#DL+" ]"
NewList otherpersons.s()
If ParseJSON(3,PB_Special_thanks$)
ExtractJSONList(JSONValue(3),otherpersons())
PrintN("Pure Basic - and others:")
ForEach otherpersons() : PrintN(otherpersons()) : Next
Else
PrintN(JSONErrorMessage() + " : " + Str(JSONErrorPosition()))
PrintN(Left(PB_Special_thanks$,JSONErrorPosition()))
PrintN(Mid(PB_Special_thanks$,JSONErrorPosition()+1))
EndIf
Input()