将Json响应作为字符串和整数发送... [英] Sending Json response as String and Integers...

查看:122
本文介绍了将Json响应作为字符串和整数发送...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{
    "UpdateRequest": {
        "SAASAS": {
            "SPO2": "99.00000",
            "VitalGroupID": "1219",
            "Temperature": "36.6666666666667",            
        },
        "Modified": 1,
        "ID": 25465
    }
}

如何发送VitalGroupID和Temperature作为整数而不是String....这是在我按下提交"按钮后形成的请求.

How can i send VitalGroupID and Temperature as Integer instead of String.... This is the request that get's formed after i hit submit button.

推荐答案

严格来说,json是无类型的,因此您不能将其作为整数发送,它必须是字符串. javascript对象不太严格,因此您拥有的对象将评估为javascript对象,但是没有严格的json解析器将能够理解它.

Strictly speaking, json is untyped, so you can't send it as an integer, it has to be a string. javascript objects are a little less strict, so what you have their will evaluate to a javascript object, but no strict json parser will be able to understand it.

您能做的最好的事情就是使用parseInt在客户端转换您知道是数字的字段.

The best you can do is to convert fields that you know are numbers on the client side using parseInt.

例如sonObj["UpdateRequest"]["SAASAS"]["VitalGroupID"] = parseInt(jsonObj["UpdateRequest"]["SAASAS"]["VitalGroupID"], 10);

这篇关于将Json响应作为字符串和整数发送...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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