Json.net遇到来自.net webservice的json字符串有问题

时间:2016-07-05 11:18:40

标签: c# asp.net json web-services

我们正在尝试解析一些json,这些json是在json.net的web服务中创建的

[
   {
      "id":"12a0910b-0196-4f1b-acff-1d395a32bbd1",
      "IVACode":"IVA001",
      "FirstName":"David",
      "LastName":"Buckley",
      "AddressLine1":"1 rathmena gardens ",
      "AddressLine2":"",
      "Town":"Ballyclare",
      "County":"Antrim",
      "PostCode":"BT3999HU",
      "Telephone":"023828392",
      "EmailAddress":"david@gmail.com",
      "isActive":true,
      "authUserName":null,
      "authCreatedDate":"2016-06-27T00:00:00",
      "personalProgressValue":5,
      "contributionsToDate":null,
      "totalContributions":null,
      "totalArrears":50000.00,
      "totalPaid":null,
      "isDeleted":false,
      "deviceId":"dwedwedwedwe",
      "deviceOs":null
   },
   {
      "id":"7aee450a-a9a7-4f19-83d3-467a3b8a39c0",
      "IVACode":"IVA002",
      "FirstName":"Peter",
      "LastName":"Carson",
      "AddressLine1":"Waters Edge Belfast",
      "AddressLine2":null,
      "Town":"Belfast",
      "County":"Down",
      "PostCode":"BT99YXX",
      "Telephone":null,
      "EmailAddress":"peter.carson@company.uk.com",
      "isActive":true,
      "authUserName":null,
      "authCreatedDate":null,
      "personalProgressValue":6,
      "contributionsToDate":null,
      "totalContributions":null,
      "totalArrears":50000.00,
      "totalPaid":null,
      "isDeleted":false,
      "deviceId":null,
      "deviceOs":null
   }
]

所以在我们的web方法中,我有以下内容来包含产生上述

的列表
 [WebMethod]
 public string getCustomerInfo()
 {
        var customerData = _dal.apertureAppstblCustomers.ToList();

        var jsonstring = JsonConvert.SerializeObject(customerData);
        jsonstring = jsonstring.Replace("<string>", "").Replace("</string>", "");

        return jsonstring;

}

但是我已经验证了json,它说它是正确的,但是当我尝试解码这个方法时,即使我尝试将其作为字符串封装进行测试,它也会失败。 Obv我们在字符串上面使用字符串 json = @&#34;&#34 ;;

JArray a = JArray.Parse(json);
foreach (JObject o in a.Children<JObject>())
{
    foreach (JProperty p in o.Properties())
    {
        string name = p.Name;
        string value = (string)p.Value;
        Console.WriteLine(name + " -- " + value);
    }       
}

0 个答案:

没有答案