Convert json string value to number

后端 未结 4 1315
孤城傲影
孤城傲影 2021-01-03 03:24

I have a JSON string that reads:

[{
    \"id\": \"id2\",
    \"index\": \"2\",
    \"str\": \"str2\",
    \"cent\": \"200\",
    \"triplet\": \"222\"
},
{
           


        
4条回答
  •  梦谈多话
    2021-01-03 03:31

    Try this. I haven't tested it but should work.

    var temp = //some json that I receive
    var jsonForChart = jQuery.extend(true, {}, temp);
    $.each(temp, function(key, value) {
        $.each(value, function(k, v) {
            if(!isNaN(parseInt(v))){
                jsonForChart[key][k] = parseInt(v);
            }else{
                jsonForChart[key][k] = v;
            }
        });
    });
    

提交回复
热议问题