JSON Implementation Example?


Tweet
(Posted 6 months ago) lavalamp

Hi,

im a noob when it comes to Json, but want to use it to store my games data, I have a correctly formatted Json file.

But admit have no idea how to implement it in NG, I see it has BRL.Json but it has no examples on how to use it.

Does someone have a simple example file for me on how to load a Json file and apply the data to an object?

Cheers, and Merry Christmas!

    Local temp:TJSON, error:TJSONError , file:TStream
    file = OpenStream:TStream( "incbin::Data/objects.json",True,False)
    temp.Load:TJSON(file,Null,error)
    ' Populate object with data using Load Method
    ' Loop through
    CloseStream file
(Posted 6 months ago) RonTek commented:

Merry Christmas lavalamp!

I haven't fully explored the default brl.json mod yet, but you can try this from mahan, of course with example.

https://www.blitzcoder.org/forum/topic.php?id=172

(Posted 6 months ago) lavalamp commented:

Whoa that looks too complicated for me :(

(Posted 6 months ago) RonTek commented:

Whoa that looks too complicated for me :(

I see. You can also try jannson, this is way more easier.

https://github.com/maxmods/bah.mod/blob/master/jansson.mod/

The example_03.bmx

SuperStrict

Framework BaH.Jansson
Import BRL.StandardIO
Import BRL.TextStream

Local text:String = LoadText("menu.json")

Local error:TJSONError

Local json:TJSON = TJSON.Load(text, 0, error)

If Not error Then

    If TJSONObject(json) Then

        For Local j:TJSON = EachIn TJSONObject(json)
            Print j.SaveString(0, 2)
        Next

    End If

End If

Reply To Topic (minimum 10 characters)

Please log in to reply