简体   繁体   English

JavaScript将数组序列化为JSON

[英]JavaScript Serialize Array to JSON

I have "Form Designer" web application, in which I need to post the controls of the new form to an ASP.Net page to insert to DB, each time I create form control. 我有“表单设计器” Web应用程序,每次创建表单控件时,都需要在其中将新表单的控件发布到ASP.Net页上,以插入到DB中。 I push it into two dimensional array, when user click save, this array will be serialized and sent to Server Page using Ajax. 我将其推入二维数组中,当用户单击“保存”时,该数组将被序列化并使用Ajax发送到服务器页面。

Array string After Serialization Looks Like : 序列化后的数组字符串如下所示:

[
    [
        {"id":"cont_menu_tb1"},
        {"name":"cont_menu_tb1"},
        {"zindex":"500"},
        {"top":"128"},
        {"left":"214"}

    ]
    ,
    [
        {"id":"cont_menu_tb2"},     
            {"name":"cont_menu_tb2"},
        {"zindex":"500"},
        {"top":"275"},
        {"left":"203"}
    ]
]

I used JSON.stringify(objCF_JSON) to serialize it. 我使用JSON.stringify(objCF_JSON)进行序列化。 Now how to De-Serialize the Array Again using Newton in VB.Net into two dimensional arrays? 现在如何再次使用VB.Net中的Newton对数组进行反序列化为二维数组?

It is not a two dimensional array, it is a single dimension array with 2 objects. 它不是二维数组,而是具有2个对象的单维数组。

List<SomeObject> objects = JsonConvert.DeserializeObject<List<SomeObject>>(json);

where SomeObject has the properties name, width, height 其中SomeObject具有属性名称,宽度,高度

您还可以使用JSON库的另一个功能将字符串反序列化为对象-JSON.parse(stringedObj)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM