<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SOE return Json with 2D array in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/soe-return-json-with-2d-array/m-p/649707#M17423</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Nevermind, I was able to just use &lt;/SPAN&gt;&lt;A href="http://james.newtonking.com/json" rel="nofollow noopener noreferrer" target="_blank"&gt;http://james.newtonking.com/json&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;List&amp;lt;List&amp;lt;int&amp;gt;&amp;gt; results = FlowTrace.RunFlowTrace(dto);
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(results));&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even using StringBuilder and it worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 03:33:36 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2021-12-12T03:33:36Z</dc:date>
    <item>
      <title>SOE return Json with 2D array</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/soe-return-json-with-2d-array/m-p/649706#M17422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;ArcGIS Server 10.11, .NET SOE&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to convert a List&amp;lt;List&amp;lt;int&amp;gt;&amp;gt; to a Json result in our .NET SOE and it keeps throwing the following error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 "error": {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; "code": 500,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; "message": "Object cannot be stored in an array of this type."
 
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

}
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code I am using.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
List&amp;lt;List&amp;lt;int&amp;gt;&amp;gt; results = UtilHelper.RunMethod();
JsonObject json = new JsonObject();
JsonObject[][] jsonResults = new JsonObject[results.Count][];
 
for (int j = 0; j &amp;lt; results.Count; j++)
{
 var list = results.ElementAt(j);
 JsonObject[] obj = new JsonObject[list.Count];
 for (var k = 0; k &amp;lt; list.Count; k++)
 {
&amp;nbsp; obj.SetValue(list.ElementAt(k), k);
 }
 jsonResults.SetValue(obj, j);
}
 
json.AddArray("results", jsonResults);
 
return Encoding.UTF8.GetBytes(json.ToJson());
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The result would look something like&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
{
&amp;nbsp; "results":[
&amp;nbsp;&amp;nbsp;&amp;nbsp; [1,2,3],
&amp;nbsp;&amp;nbsp;&amp;nbsp; [11,22,33],
&amp;nbsp;&amp;nbsp;&amp;nbsp; [], // an array could be empty
&amp;nbsp;&amp;nbsp;&amp;nbsp; [99,100,101]
&amp;nbsp; ]
}
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any insight would be greatly appreciated, thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Oct 2013 21:31:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/soe-return-json-with-2d-array/m-p/649706#M17422</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2013-10-24T21:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: SOE return Json with 2D array</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/soe-return-json-with-2d-array/m-p/649707#M17423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Nevermind, I was able to just use &lt;/SPAN&gt;&lt;A href="http://james.newtonking.com/json" rel="nofollow noopener noreferrer" target="_blank"&gt;http://james.newtonking.com/json&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;List&amp;lt;List&amp;lt;int&amp;gt;&amp;gt; results = FlowTrace.RunFlowTrace(dto);
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(results));&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even using StringBuilder and it worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:33:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/soe-return-json-with-2d-array/m-p/649707#M17423</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-12T03:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: SOE return Json with 2D array</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/soe-return-json-with-2d-array/m-p/649708#M17424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;FYI, another good JSON serializer for .NET is &lt;/SPAN&gt;&lt;A href="https://github.com/ServiceStack/ServiceStack.Text"&gt;ServiceStack.Text&lt;/A&gt;&lt;SPAN&gt;. It is supposed to &lt;/SPAN&gt;&lt;A href="https://github.com/ServiceStack/ServiceStack.Text#performance"&gt;perform better than Newtonsoft.Json&lt;/A&gt;&lt;SPAN&gt; (but I've never tested this myself). Like Newtonsoft's serializer, ServiceStack.Text is also available via NuGet.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Oct 2013 15:28:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/soe-return-json-with-2d-array/m-p/649708#M17424</guid>
      <dc:creator>JeffJacobson</dc:creator>
      <dc:date>2013-10-28T15:28:16Z</dc:date>
    </item>
  </channel>
</rss>

