My problem:
I’m writing a web app to manage contacts. On the server side, i’m working with Razor Syntax (C#) and i’m sending ajax requests to my server with a json encoded string as header. The test.cshtml recieves this as follows:
var j = Json.Decode(Request["json"]);
Now i can use all the objects perfectly fine. BUT! I have an array in the json encoded string like...,"persons":[1,2,3],... The Json.Decode decodes this as it should to an array which i can use to write data to my database. After doing this, i’d like to send the updated object back to the client (the array has not been altered or done anything else with) using:
<text>
@Html.Raw(Json.Encode(j));
@j.persons.Length;
</text>
and the output of the persons element is ...,"persons":{},..., but the length of persons is 3 as it should be. What am I doing wrong? Are there parameters to tell Json.Encode to encode sub-objects and arrays as well?
Thank you for your support
PS: @j.persons.Length is just to prove the array is not empty and existing
I found the problem. I had to strongly type the automatically generated array (from Json.Decode) with a loop:
Thank you for your approach Joseph