rain_gloom Posted June 20, 2013 Posted June 20, 2013 as stated on the wiki, the fromJSON function returns numeric indices as string indicies, but I need numeric ones. is there a wy to achieve that? My GitHub function brain() return nil end
Castillo Posted June 21, 2013 Posted June 21, 2013 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. Education is the most powerful weapon which you can use to change the world.
blehmeh Posted June 21, 2013 Posted June 21, 2013 After using fromJSON, you can use tonumber to get the numeric value of a string.
rain_gloom Posted June 21, 2013 Author Posted June 21, 2013 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
blehmeh Posted June 21, 2013 Posted June 21, 2013 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.
ixjf Posted June 21, 2013 Posted June 21, 2013 Waba: Converting a string which contains only numbers is not necessary to do arithmetic on it, refer to this example: local str, str2, str3 = "123", "2", 2 print( str + str2 ); -- "125" print( str + str3 ); -- "125" I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
Castillo Posted June 21, 2013 Posted June 21, 2013 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. Education is the most powerful weapon which you can use to change the world.
iPrestege Posted June 21, 2013 Posted June 21, 2013 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?
Castillo Posted June 21, 2013 Posted June 21, 2013 A table value, since I didn't specify any index. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now