JSON Stringify Removing Data From Object

前端 未结 1 617
星月不相逢
星月不相逢 2020-12-19 11:32

I am working on sending JSON, via jQuery ajax, to a Node server. My jQuery ajax is working. See below.

var user = JSON.stringify(userObject);
$.ajax({
               


        
相关标签:
1条回答
  • 2020-12-19 12:36

    Well, the problem is that you're creating AN ARRAY then continue working with it as with an object.

    Use

    user.regions[a] = {};
    

    instead.

    What happens is that JSON.stringify sees there is an array, tries to iterate over its numeric indexes which it does not have so it results in an empty array.

    Example on JSFiddle: http://jsfiddle.net/Le80jdsj/

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