Javascript JSON stringify No Numeric Index to include in Data

前端 未结 8 1345
天涯浪人
天涯浪人 2021-01-28 10:52

i am trying to pass non numeric index values through JSON but am not getting the data.

var ConditionArray = new Array();
ConditionArray[0] = \"1\";
ConditionArra         


        
相关标签:
8条回答
  • 2021-01-28 11:21

    This would be an better approach:

    var values = {
        array : ["1", "2", "3"],
        module : "Test",
        table : "tab_test"
    };
    var data = JSON.stringify(values);
    
    0 讨论(0)
  • 2021-01-28 11:23

    If for some reason you cannot convert your array into object, for instance you are working on a big framework or legacy code that you dont want to touch and your job is only to add som feature which requires JSON API use, you should consider using JSON.stringify(json,function(k,v){}) version of the API. In the function you can now decide what to do with value of key is of a specific type.

    0 讨论(0)
提交回复
热议问题