I receive the error "Object serialized to Property. JObject instance expected." when trying to use the following:
SortedList<string,string> results = new SortedList<string,string>();
results.Add("BOBB", "Bob Brattwurst");
results.Add("DANG", "Dan Germany");
results.Add("KON", "Konrad Plith");
JObject output = JObject.FromObject(
new JProperty("suggestions",
new JArray(
from r in results
orderby r.Value
select new JObject(
new JProperty("value", r.Key),
new JProperty("data", r.Value)
)
)
)
);
The error occurs when setting the output variable.
This is placed in a Web service, and the expected Json result should look like:
{
"suggestions": [
{ "value": "BOBB", "data": "Bob Brattwurst" },
{ "value": "DANG", "data": "Dan Germany" },
{ "value": "KON", "data": "Konraid Plith" }
]
}
I've checked against an example i found here: http://www.newtonsoft.com/json/help/html/CreatingLINQtoJSON.htm However i don't quite see the issue.