在SQL中反序列化包含多个子数组和大容量复制的Json对象

本文关键字:大容量 复制 对象 Json 数组 SQL 反序列化 包含多 | 更新日期: 2023-09-27 18:26:00

我有以下包含多个子数组的JSON数据,任何关于如何反序列化并在我的页面上打印的建议。

  • 下一步

    :在此之后,我需要使用大容量复制功能在SQL中插入这些数据。

C#代码

collect mydata= new JavaScriptSerializer().Deserialize<collect >(json);
    foreach (var item in mydata.results)
    {
    context.Response.Write(item.newPrice + item.pName);
    }
 public class collect 
    {
        public List<collection1> results { get; set; }
    }
    public class collection1
    {
        public List<data> collection1 { get; set; }
    }
    public class data
    {
        public string newPrice { get; set; }
        public string pName { get; set; }
    }

JSON数组:

{
  "name": "Test 1",
  "count": 3,
  "version": 2,
  "lastsuccess": "Thu Oct 09 2014 05:42:17 GMT+0000 (UTC)",
  "results": {
    "collection1": [
      {
        "newPrice": "12787",
        "pName": "Sony Xperia M Dual Black"
      },
      {
        "newPrice": "24999",
        "pName": "LG Google Nexus 5 16 GB (Black)"
      }
    ]
  }
}

在SQL中反序列化包含多个子数组和大容量复制的Json对象

要回答您关于如何反序列化JSON的问题,这里有一个解决方案。。。我不知道你说的"在我的页面上打印"是什么意思,因为你的问题并没有把它放在任何上下文中。。。

我曾经http://json2csharp.com要创建下面的poco类。。。

public class Collection1
{
    public string newPrice { get; set; }
    public string pName { get; set; }
}
public class Results
{
    public List<Collection1> collection1 { get; set; }
}
public class RootObject
{
    public string name { get; set; }
    public int count { get; set; }
    public int version { get; set; }
    public string lastsuccess { get; set; }
    public Results results { get; set; }
}

然后以下代码将JSON反序列化为C#。。。

RootObject myData = new JavaScriptSerializer().Deserialize<RootObject>(json);

你现在可以随心所欲地使用它,就你的批量插入而言。。。这真的是另一个问题,所以请开始新的问题。