Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

javascript - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You'll need to show the code that's creating the request when you click the button. Basically, if the object you're serializing contains numbers rather than strings, the resulting JSON will have numbers instead of strings. So the problem is that the object you're serializing has strings instead.

But for instance, if you're getting these values from HTML input fields or similar, e.g.:

UpdateRequest.SAASAS.VitalGroupID = someInputElement.value;

...value is always a string. You'll need to parse it:

UpdateRequest.SAASAS.VitalGroupID = parseInt(someInputElement.value, 10);

Note that it's best to use parseInt and to give it the radix (the number base, usually 10), else you run into issues with numbers written as "08" and similar.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...