JSON.Stringify再添引号ID [英] JSON.Stringify Adds Quotes To ID

查看:336
本文介绍了JSON.Stringify再添引号ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JSON.stringify和JSON.parse基础上更改一个在线数据库编辑我的JSON文件。一切作品的权利,但它正在围绕多​​项报价是搞砸了JSON文件。例如,它应该是标识:1 但它打印出标识:1。我将如何编辑引号呢?我preFER使用JSON.stringify,而不是替代。

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 screwing up the JSON file. For example it should be "id": 1 but it is printing out "id": "1". How would I edit the quotes out? I prefer to use JSON.stringify and not an alternative.

推荐答案

如果你正在从输入字段中的数字,数量或者其他输入始终是字符串,因此,其引用。

if you are getting the number from input field, the number or whatever input is always string and therefore its quoted.

要解决这个问题,你应该添加parseInt()函数为你的输入值,如:

To fix that you should add parseInt() for your input values like:

var value = parseInt($('#fieldID').val());

希望帮助

这篇关于JSON.Stringify再添引号ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆