Jump to content
AspNetx

Converto Output to Json

Recommended Posts

Hello everyone!I need your help.I have this code:

 @BuildTreeView(treeView, IdCategoriaParente)
@helper  BuildTreeView(IEnumerable<dynamic> data, int catfiglia, int? idcategoriaparente = 1, int level = 0, string accumulatore = ""){    //    //    var selectRecord = "";    var nodes = data.Where(n => n.IdCategoriaParente == idcategoriaparente).OrderBy(n => n.Id);    var separatore = "";    if (nodes.Any())    {        if (nodes.First().IdCategoriaParente != null)        {            if (level > 0)            {                separatore = " >> ";            }        }        if (level == 0)        {            /*            @Html.DropDownList("Direction", new List<SelectListItem>{  new SelectListItem{ Text = "Home To School", Value = "0" },  new SelectListItem{ Text = "School To Home", Value = "1" }}, new { onchange = "getAlldata()" })            */            @Html.Raw("<select name="IdCategoriaParente" id="IdCategoriaParente">");    @Html.Raw("<option value="0">Nessuna</option>");        }        foreach (var node in nodes)        {            if (node.Id == catfiglia) { selectRecord = "selected"; }            //Funzioni.SelezionaSelect(node.Id, catfiglia)            else { selectRecord = ""; }            var fullText = accumulatore + separatore + node.NomeCategoria;            @Html.Raw(string.Format("rn<option value="{0}" {2}>{1}</option>", node.Id, fullText, selectRecord));    @BuildTreeView(data, catfiglia, node.Id, level + 1, fullText);        }        if (level == 0)        {            @Html.Raw("rn</select>");        }    }    else    {        // @Html.Raw("<select name="IdCategoriaParente" id="IdCategoriaParente"><option value="0">Nessuna</option></select>");    }}

It is working properly. The problem is that now, the result is printed on the screen with a select.I wish the result was made into a JSON format: {"...", "...", "...": ...}Can you help me?Thanks in advance

Share this post


Link to post
Share on other sites

Which language are you using there? The basic idea is to build the object or array structure you need, then use a function to convert that to a JSON string.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...