C# 将json字符串转换为数据集c时出现问题?

C# 将json字符串转换为数据集c时出现问题?,c#,json,C#,Json,我试图使用JSON.Net库将JSON字符串转换为数据集。但我不断收到错误“在完成对象反序列化后在JSON字符串中找到其他文本”。我可能做错了什么 JSON字符串- [ { "title":"'Grenfell changes everything': Shadow of high-rise fire looms across UK", "pubDate":"2017-06-24 10:55:47", "link":"http://www.cnn.com

我试图使用JSON.Net库将JSON字符串转换为数据集。但我不断收到错误“在完成对象反序列化后在JSON字符串中找到其他文本”。我可能做错了什么

JSON字符串-

[
   {
      "title":"'Grenfell changes everything': Shadow of high-rise fire looms across UK",
      "pubDate":"2017-06-24 10:55:47",
      "link":"http://www.cnn.com/2017/06/24/europe/london-fire-grenfell-tower/index.html",
      "guid":"http://www.cnn.com/2017/06/24/europe/london-fire-grenfell-tower/index.html",
      "author":"",
      "thumbnail":"",
      "description":"Ten days after an inferno swept through Grenfell Tower in west London, leaving the apartment block a blackened shell and claiming the lives of at least 79 people, a shadow hangs over Britain.",
      "content":"Ten days after an inferno swept through Grenfell Tower in west London, leaving the apartment block a blackened shell and claiming the lives of at least 79 people, a shadow hangs over Britain.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170621150157-01-london-protests-0621-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Saudis: Attack foiled on Grand Mosque in Mecca",
      "pubDate":"2017-06-24 10:27:00",
      "link":"http://www.cnn.com/2017/06/23/middleeast/grand-mosque-attack-foiled/index.html",
      "guid":"http://www.cnn.com/2017/06/23/middleeast/grand-mosque-attack-foiled/index.html",
      "author":"",
      "thumbnail":"",
      "description":"Saudi security forces on Friday prevented an imminent attack on the Grand Mosque in Mecca, the country's Interior Ministry said on state-run TV.",
      "content":"Saudi security forces on Friday prevented an imminent attack on the Grand Mosque in Mecca, the country's Interior Ministry said on state-run TV.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170624130705-mecca-plot-foiled-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Qatar handed stern list of 13 demands by Arab states",
      "pubDate":"2017-06-24 09:24:20",
      "link":"http://www.cnn.com/2017/06/23/middleeast/gulf-nations-qatar-demands/index.html",
      "guid":"http://www.cnn.com/2017/06/23/middleeast/gulf-nations-qatar-demands/index.html",
      "author":"",
      "thumbnail":"",
      "description":"Four Arab states that have isolated Qatar have handed the country a list of 13 demands, including some that are likely to infuriate Doha and exacerbate the region's worst crisis in decades.",
      "content":"Four Arab states that have isolated Qatar have handed the country a list of 13 demands, including some that are likely to infuriate Doha and exacerbate the region's worst crisis in decades.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/160619161356-al-jazeera-hq-qatar-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Turkey to stop teaching evolution in high schools",
      "pubDate":"2017-06-24 06:21:59",
      "link":"http://www.cnn.com/collections/intl-turkey-evolution-theory/",
      "guid":"http://www.cnn.com/collections/intl-turkey-evolution-theory/",
      "author":"",
      "thumbnail":"",
      "description":"",
      "content":"",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170613133545-01-recep-tayyip-erdogan-0613-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"China: More than 100 feared buried in landslide",
      "pubDate":"2017-06-24 10:03:43",
      "link":"http://www.cnn.com/2017/06/23/china/china-landslide/index.html",
      "guid":"http://www.cnn.com/2017/06/23/china/china-landslide/index.html",
      "author":"",
      "thumbnail":"",
      "description":"A landslide in southwest China's Sichuan province buried more than 100 people, the Chinese state-run broadcaster China Central Television (CCTV) reported Saturday.",
      "content":"A landslide in southwest China's Sichuan province buried more than 100 people, the Chinese state-run broadcaster China Central Television (CCTV) reported Saturday.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170624160125-xinmo-landslide-distance-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Ex-Obama official: Handling of Russia 'is hardest thing to defend,' WaPo reports",
      "pubDate":"2017-06-23 17:47:54",
      "link":"http://www.cnn.com/collections/intl-wapo-former-obama-official/",
      "guid":"http://www.cnn.com/collections/intl-wapo-former-obama-official/",
      "author":"",
      "thumbnail":"",
      "description":"",
      "content":"",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170615132528-01-vladimir-putin-0615-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"White House banned cameras, so CNN sent a sketch artist",
      "pubDate":"2017-06-24 01:42:28",
      "link":"http://money.cnn.com/2017/06/23/media/white-house-press-briefing-sketch-artist/index.html",
      "guid":"http://money.cnn.com/2017/06/23/media/white-house-press-briefing-sketch-artist/index.html",
      "author":"",
      "thumbnail":"",
      "description":"",
      "content":"",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623172331-wh-briefing-colored-sketches-1-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Prosecutors ask to reinstate Hernandez's murder conviction",
      "pubDate":"2017-06-23 21:37:38",
      "link":"http://www.cnn.com/2017/06/23/us/aaron-hernandez-appeal-conviction/index.html",
      "guid":"http://www.cnn.com/2017/06/23/us/aaron-hernandez-appeal-conviction/index.html",
      "author":"",
      "thumbnail":"",
      "description":"Bristol County prosecutors officially asked to reinstate Aaron Hernandez's murder conviction on Friday, arguing in court documents that the former NFL player's suicide should not lead to dismissal of the guilty verdict.",
      "content":"Bristol County prosecutors officially asked to reinstate Aaron Hernandez's murder conviction on Friday, arguing in court documents that the former NFL player's suicide should not lead to dismissal of the guilty verdict.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170420132012-01-aaron-hernandez-court-file-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"White House responds to Comey tape inquiry with Trump tweet",
      "pubDate":"2017-06-24 10:29:09",
      "link":"http://www.cnn.com/2017/06/23/politics/white-house-comey-tapes-trump-tweet/index.html",
      "guid":"http://www.cnn.com/2017/06/23/politics/white-house-comey-tapes-trump-tweet/index.html",
      "author":"",
      "thumbnail":"",
      "description":"The White House is letting President Donald Trump's tweet Thursday -- asserting that he had not taped former FBI Director James Comey -- stand as the President's official statement.",
      "content":"The White House is letting President Donald Trump's tweet Thursday -- asserting that he had not taped former FBI Director James Comey -- stand as the President's official statement.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623093958-donald-trump-0622-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Trump faces Putin in 2 weeks",
      "pubDate":"2017-06-23 19:41:29",
      "link":"http://www.cnn.com/2017/06/23/politics/trump-putin-meeting-g20/index.html",
      "guid":"http://www.cnn.com/2017/06/23/politics/trump-putin-meeting-g20/index.html",
      "author":"",
      "thumbnail":"",
      "description":"Inside the capacious Hamburg Messe conference hall next month, President Donald Trump will come face-to-face with the man whose shadow has darkened much of his presidency: Vladimir Putin.",
      "content":"Inside the capacious Hamburg Messe conference hall next month, President Donald Trump will come face-to-face with the man whose shadow has darkened much of his presidency: Vladimir Putin.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170407053321-02-trump-putin-split-0407-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"New Zealand's All Blacks overpower Lions in series opener",
      "pubDate":"2017-06-24 11:30:20",
      "link":"http://www.cnn.com/2017/06/24/sport/new-zealand-british-and-irish-lions-rugby-eden-park-auckland/index.html",
      "guid":"http://www.cnn.com/2017/06/24/sport/new-zealand-british-and-irish-lions-rugby-eden-park-auckland/index.html",
      "author":"",
      "thumbnail":"",
      "description":"For the touring British and Irish Lions, the early signs are ominous.",
      "content":"For the touring British and Irish Lions, the early signs are ominous.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170624095656-codie-taylor-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Violent protests spread in India's Darjeeling tea lands",
      "pubDate":"2017-06-23 09:38:31",
      "link":"http://www.cnn.com/2017/06/23/asia/darjeeling-crisis-india/index.html",
      "guid":"http://www.cnn.com/2017/06/23/asia/darjeeling-crisis-india/index.html",
      "author":"",
      "thumbnail":"",
      "description":"The sleepy hills of India's northeast have erupted into violence, as calls for a separate state for the area's Nepali-speaking Gorkhas gain traction.",
      "content":"The sleepy hills of India's northeast have erupted into violence, as calls for a separate state for the area's Nepali-speaking Gorkhas gain traction.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623102753-gorkha-protest-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Air Force 'doomsday' planes damaged in tornado",
      "pubDate":"2017-06-23 22:09:54",
      "link":"http://www.cnn.com/2017/06/23/politics/air-force-planes-damaged-tornado/index.html",
      "guid":"http://www.cnn.com/2017/06/23/politics/air-force-planes-damaged-tornado/index.html",
      "author":"",
      "thumbnail":"",
      "description":"Ten US Air Force planes, including two E-4B \"doomsday\" aircraft, were damaged when a tornado hit near Offutt Air Force Base in Nebraska last week, the service told CNN on Friday.",
      "content":"Ten US Air Force planes, including two E-4B \"doomsday\" aircraft, were damaged when a tornado hit near Offutt Air Force Base in Nebraska last week, the service told CNN on Friday.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623173900-e-4b-national-airborne-operations-center-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"South Korea's new presidential pooches, and why they matter",
      "pubDate":"2017-06-24 02:54:17",
      "link":"http://www.cnn.com/2017/06/23/opinions/south-korea-dogs-animal-welfare/index.html",
      "guid":"http://www.cnn.com/2017/06/23/opinions/south-korea-dogs-animal-welfare/index.html",
      "author":"",
      "thumbnail":"",
      "description":"When South Korea's new president Moon Jae-in took up residency in the Blue House last month, his choice of pets raised some eyebrows.",
      "content":"When South Korea's new president Moon Jae-in took up residency in the Blue House last month, his choice of pets raised some eyebrows.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170606205829-s-korea-dog-breeders-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Al Jazeera: What you need to know",
      "pubDate":"2017-06-23 16:01:18",
      "link":"http://www.cnn.com/videos/cnnmoney/2017/06/23/al-jazeera-explainer-mxb-lon-orig.cnnmoney",
      "guid":"http://www.cnn.com/videos/cnnmoney/2017/06/23/al-jazeera-explainer-mxb-lon-orig.cnnmoney",
      "author":"",
      "thumbnail":"",
      "description":"CNN's Frederik Pleitgen takes a look at the controversies surrounding this global news network based in Qatar.",
      "content":"CNN's Frederik Pleitgen takes a look at the controversies surrounding this global news network based in Qatar.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623165833-al-jazeera-1-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"The world will solve its own problems -- with or without Trump",
      "pubDate":"2017-06-23 11:36:51",
      "link":"http://www.cnn.com/2017/06/23/opinions/us-global-leadership-robertson/index.html",
      "guid":"http://www.cnn.com/2017/06/23/opinions/us-global-leadership-robertson/index.html",
      "author":"",
      "thumbnail":"",
      "description":"It's been a blistering week in London, with little shade from the sun or the news.",
      "content":"It's been a blistering week in London, with little shade from the sun or the news.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170602164707-trump-world-leaders-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"US releases dramatic photos of 'unsafe' Russian jet intercept",
      "pubDate":"2017-06-23 18:16:02",
      "link":"http://www.cnn.com/2017/06/23/politics/russian-jet-intercepts-us-aircraft-photos/index.html",
      "guid":"http://www.cnn.com/2017/06/23/politics/russian-jet-intercepts-us-aircraft-photos/index.html",
      "author":"",
      "thumbnail":"",
      "description":"US European Command released dramatic photos on Thursday that show the moment a Russian Su-27 fighter jet flew within five feet of a US Air Force RC-135 reconnaissance aircraft over the Baltic Sea -- an encounter US officials assessed to be \"unsafe.\"",
      "content":"US European Command released dramatic photos on Thursday that show the moment a Russian Su-27 fighter jet flew within five feet of a US Air Force RC-135 reconnaissance aircraft over the Baltic Sea -- an encounter US officials assessed to be \"unsafe.\"",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623121807-russian-unsafe-intercept-01-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"May's Brexit divorce deal branded 'not sufficient'",
      "pubDate":"2017-06-23 13:40:08",
      "link":"http://www.cnn.com/2017/06/23/europe/eu-nationals-brexit-may/index.html",
      "guid":"http://www.cnn.com/2017/06/23/europe/eu-nationals-brexit-may/index.html",
      "author":"",
      "thumbnail":"",
      "description":"British Prime Minister Theresa May's plans to secure the rights of EU nationals after Brexit have been criticized as \"not sufficient,\" by the head of the European Commission.",
      "content":"British Prime Minister Theresa May's plans to secure the rights of EU nationals after Brexit have been criticized as \"not sufficient,\" by the head of the European Commission.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623094855-04-theresa-may-brussels-0623-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"No break for Britain: 5 tragedies in 3 months",
      "pubDate":"",
      "link":"http://cnn.it/2rLuYi4",
      "guid":"http://cnn.it/2rLuYi4",
      "author":"",
      "thumbnail":"",
      "description":"",
      "content":"",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170623162903-01-uk-tragedies-cnnphotos-super-169.jpg"
      },
      "categories":[

      ]
   },
   {
      "title":"Splash 'dancing' at the Dallas Zoo with Zola the gorilla",
      "pubDate":"2017-06-24 11:51:21",
      "link":"http://www.cnn.com/2017/06/24/us/dallas-zoo-dancing-gorilla-trnd/index.html",
      "guid":"http://www.cnn.com/2017/06/24/us/dallas-zoo-dancing-gorilla-trnd/index.html",
      "author":"",
      "thumbnail":"",
      "description":"There seems to be a lot more going on behind the scenes at the Dallas Zoo -- including some splashy dance moves by Zola the gorilla.",
      "content":"There seems to be a lot more going on behind the scenes at the Dallas Zoo -- including some splashy dance moves by Zola the gorilla.",
      "enclosure":{
         "link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170624051705-dallas-zoo-gorilla-zola-splash-pool-sot-nr-00002328-super-169.jpg"
      },
      "categories":[

      ]
   }]
这就是我试过的

[WebMethod]
    public string RSSfeeddata(string info) {

        SqlConnection con = new SqlConnection(
    WebConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString);
        var outObject = JsonConvert.DeserializeObject(info);
        DataSet myDataSet = JsonConvert.DeserializeObject<DataSet>(info);     
        return info;
    }

将Json反序列化到数据集中的唯一方法是首先从数据集中序列化它。相反,您可以创建一个使用Json的类。为此,将Json复制到剪贴板中,在Visual Studio中创建一个新的.Json文件,单击“编辑”菜单,转到“粘贴特殊”,然后将Json粘贴为类。对我来说,它产生了

public class Class1
{
    public string title { get; set; }
    public string pubDate { get; set; }
    public string link { get; set; }
    public string guid { get; set; }
    public string author { get; set; }
    public string thumbnail { get; set; }
    public string description { get; set; }
    public string content { get; set; }
    public Enclosure enclosure { get; set; }
    public object[] categories { get; set; }
}

public class Enclosure
{
    public string link { get; set; }
}
然后将json读入IEnumerable,我没有按如下方式重命名该类

var text = System.IO.File.ReadAllText("json1.json");

var items = JsonConvert.DeserializeObject<IEnumerable<Class1>>(text);

然后,您可以使用IEnumerable代替数据集。

我看不出您的JSON中有任何问题,但我注意到:第一个标题是“Grenfell改变一切”:高楼大火的阴影笼罩着英国。这个值是一种JSON格式,也许JsonConvert正在尝试转换它also@ElmerDantas我只是运行了相同的json通过我的电脑上的JsonConvert,它可以正常工作。它是一个带引号的字符串@ElmerDantas@EdPlunkett我知道它是…是一个有效的json,但正如我所说的,json转换器正试图将json内部的这一部分转换为json,这也是一个疑问。您所能做的最好的事情就是创建一个具有所需属性的对象,然后使用该对象进行反序列化@是埃尔默丹塔斯,还是你只是想知道是不是?你能给我看一个演示这个bug的特殊序列化程序的例子吗?