serialize json to json array

Hi! i have serialize object to be like this:
{id_krs:123,detail_jawaban:[a,b,c,d],id_pertanyaan:[1,2,3,4]}
How can i change it to be like this:
{
[id_krs:123,detail_jawaban:a,id_pertanyaan:1],
[id_krs:123,detail_jawaban:b,id_pertanyaan:2],
[id_krs:123,detail_jawaban:c,id_pertanyaan:3],
[id_krs:123,detail_jawaban:d,id_pertanyaan:4]
}
i need your help please
Thanks before

Answers

  • ArvindrajaArvindraja INMember ✭✭✭
    edited November 2017

    Try something like below

     public class MyData
    {
      public int id_krs {get;set;}
      public string detail_jawaban{get;set;}
      public int id_pertanyaan{get;set;}
    }
    
    var list = JArray.Parse(response);
                  var  _list = list.Select(c => new  MyData{ id_krs = c.Value<int>("id_krs "), detail_jawaban= c.Value<string>("detail_jawaban"),id_pertanyaan= c.Value<int>("id_pertanyaan") }).ToList();
    
  • robbitrobbit CNMember Xamurai

    Hi,

    {id_krs:123,detail_jawaban:[a,b,c,d],id_pertanyaan:[1,2,3,4]}
    

    and

    {
    [id_krs:123,detail_jawaban:a,id_pertanyaan:1],
    [id_krs:123,detail_jawaban:b,id_pertanyaan:2],
    [id_krs:123,detail_jawaban:c,id_pertanyaan:3],
    [id_krs:123,detail_jawaban:d,id_pertanyaan:4]
    }
    

    They are not Json format. Are you sure this is what you want?
    refer to this

Sign In or Register to comment.