Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Json response as String and Integers...

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

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.

like image 685
John Cooper Avatar asked Jul 28 '11 11:07

John Cooper


1 Answers

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.

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

e.g. sonObj["UpdateRequest"]["SAASAS"]["VitalGroupID"] = parseInt(jsonObj["UpdateRequest"]["SAASAS"]["VitalGroupID"], 10);

like image 134
Charles Ma Avatar answered Oct 20 '22 16:10

Charles Ma