最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Convert a JavaScript array into a C# List - Stack Overflow

programmeradmin1浏览0评论

Following is my javascript array which I am passing from the server.

string request = @"[[1,""Name"",""Sam"",""20""],1,""Name"",""Ram"",""20""]]";

I want to convert it into a List of C# object.

public class UpdateData
    {
        public int RowID { get; set; }

        public string ColumnName { get; set; }

        public string OldValue { get; set; }

        public string NewValue { get; set; }

    }

Is there a way to do that?

Following is my javascript array which I am passing from the server.

string request = @"[[1,""Name"",""Sam"",""20""],1,""Name"",""Ram"",""20""]]";

I want to convert it into a List of C# object.

public class UpdateData
    {
        public int RowID { get; set; }

        public string ColumnName { get; set; }

        public string OldValue { get; set; }

        public string NewValue { get; set; }

    }

Is there a way to do that?

Share Improve this question edited Mar 21 at 20:47 TylerH 21.1k78 gold badges79 silver badges114 bronze badges asked May 23, 2014 at 17:45 MuthukumarMuthukumar 9,63918 gold badges66 silver badges87 bronze badges 1
  • 3 The easy way would be to use JSON... There are plenty of good librairies to help with serializing/deserializing (check Newtonsoft.Json) – Bun Commented May 23, 2014 at 17:48
Add a ment  | 

2 Answers 2

Reset to default 8

First get a List of Lists and then loop over it to form your List of UpdateData (using Json.Net)

 var obj = JsonConvert.DeserializeObject <List<List<object>>>(request);

You'll want a Json parser. Use Nuget to add one to your project: Install-Package Newtonsoft.Json

发布评论

评论列表(0)

  1. 暂无评论