Json.stringify Adds Quotes To Id
I'm using JSON.stringify and JSON.parse to edit my JSON file based on changes to an online database. Everything works right, except it is making quotes around a number which is scr
Solution 1:
if you are getting the number from input field, the number or whatever input is always string and therefore its quoted.
To fix that you should add parseInt() for your input values like:
var value = parseInt($('#fieldID').val());
Hope that helps
Solution 2:
1
must not be a true integer to begin with. Executing JSON.stringify({id: 1})
in the console will return "{"id":1}"
. How are you defining the value for id
? I'm guessing at that point, it is getting saved as a string (i.e. {id: "1"}
).
Post a Comment for "Json.stringify Adds Quotes To Id"