Page 1 of 1

ExtractJSONStructure form file

Posted: Sat Mar 26, 2016 11:31 pm
by Arbrakaan
What i'm doing wrong?, i get nothing from the file, but it is well loaded :

Code: Select all

Structure config
  Name$
  Age.l
  List Books.s()
EndStructure

  LoadJSON(0,"config.json")

  ExtractJSONStructure(JSONValue(0), @P.config, config)
  
  Debug P\Name$
  Debug P\Age
  Debug ListSize(P\Books())
and my JSON file : config.json

Code: Select all

{"Name": "John Smith", "Age": 42, "Books": ["Investing For Dummies", "A Little Bit of Everything For Dummies"] }

Re: ExtractJSONStructure form file

Posted: Sun Mar 27, 2016 2:06 am
by Peter
you need a callback:

Code: Select all

Structure config
  Name$
  Age.l
  List Books.s()
EndStructure

Procedure LoadingEvent(Type, Filename$, ObjectId)
	
  Debug Type ; should be #PB_Loading_JSON
  Debug Filename$ ; should be "config.json"
  Debug ObjectId ; should be 0
	
  ExtractJSONStructure(JSONValue(ObjectId), @P.config, config)
  
  Debug P\Name$
  Debug P\Age
  Debug ListSize(P\Books())
  
EndProcedure

BindEvent(#PB_Event_Loading, @LoadingEvent())

LoadJSON(0, "config.json")
Greetings ... Peter

Re: ExtractJSONStructure form file

Posted: Sun Mar 27, 2016 8:47 am
by Arbrakaan
Thanks Peter for your help,
have a good day !

Re: ExtractJSONStructure form file

Posted: Sun Mar 27, 2016 11:06 am
by Fred
I will probably change all LoadXXX() commands to requiers a callback parameter, so it will be easier to spot the change when coming from PureBasic.