I'm using ArcGIS Server 10.11, .NET SOE.I'm trying to convert a List<List<int>> to a Json result in our .NET SOE and it keeps throwing the following error.
{
"error": {
"code": 500,
"message": "Object cannot be stored in an array of this type."
}
}
Here is the code I am using.
List<List<int>> results = UtilHelper.RunMethod();
JsonObject json = new JsonObject();
JsonObject[][] jsonResults = new JsonObject[results.Count][];
for (int j = 0; j < results.Count; j++)
{
var list = results.ElementAt(j);
JsonObject[] obj = new JsonObject[list.Count];
for (var k = 0; k < list.Count; k++)
{
obj.SetValue(list.ElementAt(k), k);
}
jsonResults.SetValue(obj, j);
}
json.AddArray("results", jsonResults);
return Encoding.UTF8.GetBytes(json.ToJson());
The result would look something like
{
"results":[
[1,2,3],
[11,22,33],
[], // an array could be empty
[99,100,101]
]
}
Eventually, we're going to refactor this out to build JsonObject[] using that helper method, but for now, I just need to convert this so we don't have to update much more on the client side other than the URL endpoints.I'm a little stumped on this one. If I parse the results using StringBuilder, they come out ok, but then they are not JSON and I can't parse them on the client side.I can't find much info in the docs for JsonObject and it looks like there is a JSONArray, but I'm unsure how to use that or even if I should.Any insight would be greatly appreciated, thanks!