我有以下組可變JSON數據的其中第一行是元素名稱和其他行的列表中表示元件的值的列表:變換嵌套JSON陣列成JSON對象的數組
[
[
"category",
"author",
"title",
"price"
],
[
"reference",
"Nigel Rees",
"Sayings of the Century",
"8.95"
],
[
"fiction",
"Evelyn Waugh",
"Sword of Honour",
"12.99"
],
[
"fiction",
"Herman Melville",
"Moby Dick",
"8.99"
],
[
"fiction",
"J. R. R. Tolkien",
"The Lord of the Rings",
"22.99"
]
]
我想從數據構建以下類型的JSON對象:
{
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
}
如何建立這應該是等同於我上面的JSON對象。我沒有看到任何直接支持使用JSON.NET API來做到這一點。 任何幫助,不勝感激。
這看起來更像是某種CSV數據。 – Jerodev
請分享您嘗試過的內容。這不是一個代碼服務網站。迭代每一行,將其解析爲相應的對象,添加到結果集合,然後轉換爲JSON。請參閱[如何提問](https://stackoverflow.com/help/how-to-ask),瞭解如何發佈一個好問題 –