asp.net - How do i create name of List dynamically? -


i trying create =>

{   "data1":{      "datalistone": [0, 1],      "datalisttwo": [1, 0, 0, 0]           },   "data2":{      "datalistone": [1, 0],      "datalisttwo": [0, 0, 0, 1]           },   "data-n" : {       "datalistone": [1, 0],      "datalisttwo": [0, 1, 0, 0]           }  } 

list dynamically starting data1 data-n not specified @ point need stop list , want 2 list (datalistone, datalisttwo) inside data1 data-n.

i not getting how create list dynamically data1 data-n , 2 list (datalistone, datalisttwo) inside dynamic list data1 data-n

please me this.

i'd use json.net - lets build json dynamically:

using system; using system.collections.generic; using system.linq; using newtonsoft.json.linq;  class program {     static void main(string[] args)     {         var pairs = new list<listpair>         {             new listpair             {                 datalistone = { 0, 1 },                 datalisttwo = { 1, 0, 0, 0 }             },             new listpair             {                 datalistone = { 1, 0 },                 datalisttwo = { 0, 0, 0, 1 }             },             new listpair             {                 datalistone = { 1, 0 },                 datalisttwo = { 0, 1, 0, 0 }             },         };          jobject json = createjson(pairs);         console.writeline(json);     }      static jobject createjson(list<listpair> pairs)     {         return new jobject(pairs.select(            (pair, index) => new jproperty("data" + (index + 1),                                           jobject.fromobject(pair))));      }      class listpair     {         public list<int> datalistone, datalisttwo;          public listpair()                     {             datalistone = new list<int>();             datalisttwo = new list<int>();         }     } } 

on other hand, think cleaner create array in json rather having names generated dynamically.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -