ExtractJSONStructure form file

Just starting out? Need help? Post your questions and find answers here.
User avatar
Arbrakaan
Posts: 91
Joined: Mon Feb 24, 2014 10:54 pm
Location: Geneva
Contact:

ExtractJSONStructure form file

Post 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"] }
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: ExtractJSONStructure form file

Post 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
User avatar
Arbrakaan
Posts: 91
Joined: Mon Feb 24, 2014 10:54 pm
Location: Geneva
Contact:

Re: ExtractJSONStructure form file

Post by Arbrakaan »

Thanks Peter for your help,
have a good day !
Last edited by Arbrakaan on Sun Mar 27, 2016 12:31 pm, edited 1 time in total.
Fred
Site Admin
Posts: 1821
Joined: Mon Feb 24, 2014 10:51 am

Re: ExtractJSONStructure form file

Post 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.
Post Reply