rain_gloom Posted June 20, 2013 Share 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? Link to comment
Castillo Posted June 21, 2013 Share Posted June 21, 2013 I don't really understand what you said. fromJSON returns a table out of a valid JSON string. Link to comment
blehmeh Posted June 21, 2013 Share Posted June 21, 2013 After using fromJSON, you can use tonumber to get the numeric value of a string. Link to comment
rain_gloom Posted June 21, 2013 Author Share 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. Link to comment
blehmeh Posted June 21, 2013 Share 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. Link to comment
ixjf Posted June 21, 2013 Share 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" Link to comment
Castillo Posted June 21, 2013 Share 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 ) ) Link to comment
iPrestege Posted June 21, 2013 Share 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? Link to comment
Castillo Posted June 21, 2013 Share Posted June 21, 2013 A table value, since I didn't specify any index. Link to comment
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