Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...