I'm writing a Xamarin app that uses Newtonsoft.Json and I'm having trouble with the following error message:
"Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'learningAndroidICS.memberInfo' because the type requires a JSON object to deserialize correctly. To fix this error either change the JSON to a JSON objecct or change the deserialized type to an array or a type that implements a collection interace like List that can be serialized from a JSON array."
Considering that my code looks like this:
currentMember = JsonConvert.DeserializeObject<memberInfo> (content);
where currentMember is an instance of the memberInfo class, which looks like this:
using System;
namespace learningAndroidICS
{
public class memberInfo
{
public string id { get; set; }
public string lastName { get; set; }
public string firstName1 { get; set; }
public string firstName2 { get; set; }
public string address1 { get; set; }
public string address2 { get; set; }
public string childName1 { get; set; }
public string childName2 { get; set; }
public string childName3 { get; set; }
public string childName4 { get; set; }
public string childName5 { get; set; }
public string childName6 { get; set; }
public string childName7 { get; set; }
public string childName8 { get; set; }
public string childName9 { get; set; }
public string childName10 { get; set; }
public string childDOB1 { get; set; }
public string childDOB2 { get; set; }
public string childDOB3 { get; set; }
public string childDOB4 { get; set; }
public string childDOB5 { get; set; }
public string childDOB6 { get; set; }
public string childDOB7 { get; set; }
public string childDOB8 { get; set; }
public object childDOB9 { get; set; }
public string childDOB10 { get; set; }
public string dateActivated { get; set; }
public string dateDeactivated { get; set; }
public string isActive { get; set; }
public int membershipType { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zip { get; set; }
public string email { get; set; }
public memberInfo ()
{
}
}
}
The JSON string (comes from a webservice) looks like this:
[
{
"id": "8",
"lastName": "Smith",
"firstName1": "John",
"firstName2": "Jane",
"address1": "123 Fake Ave",
"address2": "",
"childName1": "Bill",
"childName2": "John",
"childName3": "Jim",
"childName4": "",
"childName5": "",
"childName6": "",
"childName7": null,
"childName8": null,
"childName9": null,
"childName10": null,
"childDOB1": "11/02/1991",
"childDOB2": "22/10/1992",
"childDOB3": "11/08/1998",
"childDOB4": "",
"childDOB5": "",
"childDOB6": "",
"childDOB7": null,
"childDOB8": null,
"childDOB9": null,
"childDOB10": null,
"dateActivated": "26/11/2014",
"dateDeactivated": "",
"isActive": "1",
"membershipType": null,
"city": "Fake",
"state": "MI",
"zip": "12345",
"email": "[email protected]"
}
]