Jump to content

fromJSON indices


Recommended Posts

Posted

I don't really understand what you said.

fromJSON returns a table out of a valid JSON string.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

So I should format the returned string. Hmm...how? Could someone give an example?

(the final code should be really efficient)

as I see the solution:

I have a JSON formatted string: s

I traverse this string, searching for a pattern like: ["N"], where N is an integer

If I find one, I clear two characters before and after it.

My GitHub

function brain()   return nil end 
Posted

What I originally meant:

local string = "1" 
local number = tonumber(string) + 1 
print (number) --outputs 2 

After using fromJSON, you can then loop through the returned table to find numeric values.

Posted
So I should format the returned string. Hmm...how? Could someone give an example?

(the final code should be really efficient)

as I see the solution:

I have a JSON formatted string: s

I traverse this string, searching for a pattern like: ["N"], where N is an integer

If I find one, I clear two characters before and after it.

I still don't understand, converting a table into a JSON string won't change how the table is ordered or made.

Example:

myJSON = toJSON ( { [ 1 ] = "Hello", [ 2 ] = "World" } ) 
outputChatBox ( myJSON ) 
myTable = fromJSON ( myJSON ) 
outputChatBox ( tostring ( myTable ) ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
So I should format the returned string. Hmm...how? Could someone give an example?

(the final code should be really efficient)

as I see the solution:

I have a JSON formatted string: s

I traverse this string, searching for a pattern like: ["N"], where N is an integer

If I find one, I clear two characters before and after it.

I still don't understand, converting a table into a JSON string won't change how the table is ordered or made.

Example:

myJSON = toJSON ( { [ 1 ] = "Hello", [ 2 ] = "World" } ) 
outputChatBox ( myJSON ) 
myTable = fromJSON ( myJSON ) 
outputChatBox ( tostring ( myTable ) ) 

What would the result be for myTable?

  

Posted

A table value, since I didn't specify any index.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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