1

We are having allot issues trying to decode some json which was created in our webservice from json.net

[
   {
      "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
   }
]

So in our web method I have the following to enclode a list which produces the above

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

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

        return jsonstring;

}

But I have validated the json and it says its correct but when i try to decode this method it fails even when i try to enclose it as a string for testing. Obv we used the string json =@ ""; above string

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);
    }       
}
Sascha
  • 10,231
  • 4
  • 41
  • 65
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • serializers often have issues with serializing DateTime properly. Try to remove datetime field and test again. – Mikolaytis Jul 05 '16 at 11:23
  • @Mikolaytis we tried with double quotes and it it delzieraized ok if that gives you an idea ?. – c-sharp-and-swiftui-devni Jul 05 '16 at 11:25
  • What are the actual results and what is the problem? JSon.NET doesn't have problems with dates, whether ISO8601 (as in your case) or the deprecated `Date(\...` format. Does `Parse` throw or do you get unexpected results in the loop? – Panagiotis Kanavos Jul 05 '16 at 11:37
  • You also *don't* need to use `Children()`, just `Children()` . Check [this similar question](http://stackoverflow.com/questions/16045569/how-to-access-elements-of-a-jarray), it uses `array.Children()` and `item.Children()` to get to the properties. – Panagiotis Kanavos Jul 05 '16 at 11:42
  • @PanagiotisKanavos I am having to place double quotes around the text I am using xamrian for andriod development studio and I think its interfearing there – c-sharp-and-swiftui-devni Jul 06 '16 at 12:14

0 Answers0