Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to load a JSON object from file in Tier 1?

Author
Message
Zigi
14
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 20th May 2018 22:27 Edited at: 20th May 2018 22:32
Hi.

I would like to load a JSON object from file in Tier 1.
I did come across the API by MadBit:
https://forum.thegamecreators.com/thread/218297#postHolder

I was trying to ask for help but unfortunately the thread has been closed.
I can't figure out how to load objects using the API I'm getting can not convert types and -1, 0 and empty string but I can not get any value from the JSON.
This is the JSON I'm trying:

file.json



I was trying to work my way down, try to get the first object and it properties, the second object and it properties and finally the array but I failed right at the beginning.
All I get is -1, 0 or an empty string if not an error message saying can not convert data types.

Could anyone help me with the JSON API of MadBit how to get the first object and it properties, the second object and it properties and the array and it elements?

I would appreciate any help.
Thank you.
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 21st May 2018 00:48
First, a small bug in your json file. You need a comma after the 40 in line 8.

A json file represents a Type with all its fields and subtypes. Each key in the json file represents a field in the type, and the key's value is the field's value. In your example, you need a type with fields named "property1", "property2", and "array". You also need a type with fields named "element1" and "element2" , and one type with fields "object1" and "object2"


I really don't think this is what you intended. It looks like you intended to have a list of objects which can contain an array of elements. In that case, you can dispense with the "object1/object2" and "element1/element2" and just use json's array notation.


Then you can add as many objects and elements that you need, as the code below shows.


MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 21st May 2018 06:55
TomToad is right. My JSON library was created when AppGameKit did not support the JSON format. It is recommended to use the AGK-Buildin commands.

If you still want to take my library, this should work. After you've added the comma, as TomToad has already mentioned.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Zigi
14
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 21st May 2018 08:05 Edited at: 21st May 2018 08:07
Thank you both.
The JSON is actually coming from a 3rd party tool and this is the basic structure (except the error I made with the comma) of the JSON.
I didn't know that AppGameKit do support JSON now I was searching the docs and all I did find is the networking commands I was hoping to find something more "dedicated" approach like the JSON API
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 21st May 2018 10:18
The commands are hidden away under Documentation/Principles/Arrays in version 2 at the very bottom of the document here https://www.appgamekit.com/documentation/guides/12_array_changes.htm.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 21st May 2018 10:38
@Madbit, I'm still using your code
I started writing my app before the official solution, and I have no reason to fix what isn't broken.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 21st May 2018 10:49

That's nice to hear that the API is still in use.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2024-04-19 14:49:20
Your offset time is: 2024-04-19 14:49:20