ExtractJSONMap() problem

Just starting out? Need help? Post your questions and find answers here.
tua
User
User
Posts: 68
Joined: Sun Jul 23, 2023 8:49 pm
Location: BC, Canada

ExtractJSONMap() problem

Post by tua »

Code: Select all

Input$   = "{" + Chr(34) + "14" + Chr(34) + ": "  + Chr(34) + "Joe"  + Chr(34) + "," + 
                 Chr(34) + "22" + Chr(34) + ": "  + Chr(34) + "Jim"  + Chr(34) + "," +  
                 Chr(34) + "5"  + Chr(34) + ": "  + Chr(34) + "Mark" + Chr(34) + "}" 

j = ParseJSON(0, Input$)

If IsJSON(j) 
  NewMap Options()
  ExtractJSONMap(JSONValue(0), Options())   
  ForEach Options()
    Debug MapKey(Options()) + Options()
  Next
EndIf
This does not print out the key/value pairs I am expecting here, but rather the numbers: 140, 220, 50 - i.e. my keys multiplied by 10. What am I missing?
normeus
Enthusiast
Enthusiast
Posts: 477
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: ExtractJSONMap() problem

Post by normeus »

The map should be a string type:

Code: Select all

Input$   = "{" + Chr(34) + "14" + Chr(34) + ": "  + Chr(34) + "Joe"  + Chr(34) + "," + 
                 Chr(34) + "22" + Chr(34) + ": "  + Chr(34) + "Jim"  + Chr(34) + "," +  
                 Chr(34) + "5"  + Chr(34) + ": "  + Chr(34) + "Mark" + Chr(34) + "}" 

Debug input$
j = ParseJSON(0, Input$)
Debug JSONErrorMessage()
If IsJSON(0) 
  NewMap Options.s() ; <------------------------ string
  ExtractJSONMap(JSONValue(0 ), Options())   
  ForEach Options()
     key$ = MapKey(Options())
      Debug Options(key$)+" "+ key$
 Next
Else
   Debug "NO JSON"
EndIf
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
tua
User
User
Posts: 68
Joined: Sun Jul 23, 2023 8:49 pm
Location: BC, Canada

Re: ExtractJSONMap() problem

Post by tua »

Yes, it should! :oops: Thanks!
Post Reply