Jump to content

[HELP] Inserting map elements into JSON


..:D&G:..

Recommended Posts

Hello guys, I am trying to add map elements like objects, markers, vehicles etc into JSON as someone told me I can easily do

local theElements = fromJSON("["..mapElements.."]") 

The thing is that I don't know how to use JSON, as I never used it before. From what I understand, I need my script to be something like this:

local theElements = fromJSON("["..mapElements.."]") 
        if theElements then 
            local objectElements = theElements['object'] 
            local markerElements = theElements['marker'] 

But I don't know how JSON works, how I insert the data and how it is stored in JSON...

Thanks.

Link to comment
toJSON({}) --> "[ [ ] ]" 
fromJSON("[ [ ] ]") --> {} -- Empty Lua table 

local t = {} 
table.insert(t, "CIT") 
local j = toJSON(t)          --> "[ [ 'CIT' ] ]" 
local t2 = fromJSON(j)    --> {[1] = "CIT"} 
table.insert(t2, "FFS")      --> {[1] = "CIT", [2] = "FFS"} 
toJSON(t2)                   --> "[ [ 'CIT', 'FFS' ] ]" 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...