The complete objects you are looking for should be structured as:
[DataContract(Name="response")]
public class Response
{
[DataMember(Name = "locations")]
public IEnumerable<Location> Locations { get; set; }
[DataMember(Name = "error")]
public string Error { get; set; }
}
[DataContract(Name = "location")]
public class Location
{
[DataMember(Name = "id")]
public string Id { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "statusid")]
public string StatusId { get; set; }
}
, { }, IEnumerable/array, [ ] JSON.
, , , , JSON . , , JSON XML Serialization - ASP.NET.
vittore , JSON , :
[DataContract]
public class ResponseParent
{
[DataMember(Name = "response")]
public Response ResponseInstance { get; set; }
}
[DataContract]
public class Response
{
[DataMember(Name = "locations")]
public LocationCollectionIntermediate Locations { get; set; }
[DataMember(Name = "error")]
public string Error { get; set; }
}
[DataContract]
public class LocationCollectionIntermediate
{
[DataMember(Name = "location")]
public IEnumerable<Location> Locations { get; set; }
}
[DataContract]
public class Location
{
[DataMember(Name = "id")]
public string Id { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "statusid")]
public string StatusId { get; set; }
}
, . , JSON, Id int.
, WCF JSON, :
string json;
using (var ms = new MemoryStream())
{
var ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(ResponseParent));
ser.WriteObject(ms, r);
json = System.Text.Encoding.UTF8.GetString(ms.GetBuffer(), 0, Convert.ToInt32(ms.Length));
}
DataContractJsonSerializer
, - RESTful, JSON WCF RESTful Service 60 .