Hello all. I'm kind of a newbie using JSON serialization, so any help would be greatly appreciated! Plus, I'm at my wits end. I'm using the standard Newtonsoft JSON serializer and I need to somehow get my directoryIds property to serialize
exactly like result #2 below. Currently, I'm getting result #1. I checked to make sure both were valid JSON formats using this Web validator :
http://jsonformatter.curiousconcept.com/[
^]. I've only posted a partial JSON object for reference.
...
[DataMember]
public DirectoryId[] directoryIds { get; set; }
...
[DataContract]
public class DirectoryId
{
[DataMember]
[JsonProperty(PropertyName = "string")]
public string Str { get; set; }
}
Here's the code to serialize the object just in case it's pertinent :
public class RestSharpJsonSerializer : ISerializer
{
public string Serialize(object obj)
{
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented });
}
public string RootElement { get; set; }
public string Namespace { get; set; }
public string DateFormat { get; set; }
public string ContentType
{
get { return "application/json"; }
set { }
}
}
Result #1
"searchScope":"IndividualProvidersOnly",<br />
"directoryIds":[<br />
{<br />
"string":"NGX"<br />
},<br />
{<br />
"string":"MDA"<br />
}<br />
],<br />
"resultSizeLimit":10,
Result #2
"searchScope":"IndividualProvidersOnly",<br />
"directoryIds":[<br />
{<br />
"string":"NGX",<br />
"string":"MDA"<br />
}<br />
],<br />
"resultSizeLimit":10,
Ending the week like this is really bugging me so I'm looking forward to any help I can get over the next few days. Thank you everyone!