2016-03-10 55 views
0

我得到以下JSON數據:沒有對象的屬性名

[ 
    { 
    "Data": [ 
     [915408000000,1.1789], 
     [915494400000,1.179] 
    ] 
    } 
] 

但我不想屬性名稱「數據」,我想這一點:

[ 
     [915408000000,1.1789], 
     [915494400000,1.179] 
] 

代碼作出上述JSON數據:

var myJsonObList = new List<MyCurrencyJsonBuilder>(); 
    var list = // I am getting data from sqlServer in a list; 
    var myJsonObj = new MyCurrencyJsonBuilder(list); 
    myJsonObList.Add(myJsonObj); 
    //send response with json 
    context.Response.Write(JsonConvert.SerializeObject(myJsonObList)); 

類別:

class MyCurrencyJsonBuilder 
     { 
     List<List<dynamic>> _data { get; set; } 

      public MyCurrencyJsonBuilder(List<List<dynamic>> currencydata) 
      { 

       this._data = currencydata; 
      } 

      public List<List<dynamic>> Data 
      { 
       get { return _data; } 
      } 

     } 
+2

您可以使用自定義的Json轉換器。看到這裏:http://stackoverflow.com/questions/11934487/custom-json-serialization-of-class 對我來說,雖然,你似乎是序列化與Data屬性的對象,當你需要序列化數據屬性。 –

回答

0
var json = @" 
[ 
    { 
    ""Data"": [ 
     [915408000000, 1.1789], 
     [915494400000,1.179] 
    ] 
    } 
]"; 

var jToken = JsonConvert.DeserializeObject<JToken>(json); 
var jArray = new JArray(); 
foreach (var token in jToken) 
{ 
    jArray.Add(token["Data"].Children()); 
} 
var responseJson = JsonConvert.SerializeObject(jArray); 
// responseJson = [[915408000000,1.1789],[915494400000,1.179]]