-3
我想通過JSON對象列表循環並將它們轉換爲索引JSON。Int未在JSON對象中顯示爲字符串
下面是我寫的代碼:
private string ItemsAsJson(List<string> jsonItemList)
{
string ItemAsJson = "";
for (int i = 0; i < jsonItemList.Count; i++)
{
string index = i.ToString();
ItemAsJson += "{ " + index + " : " + jsonItemList[i] + "},";
}
return ItemAsJson;
}
但我得到的對象,如下位置:
{
0: {
"item_type": "Batch",
"item_id": "82",
"bill_item_name": "A TO Z",
"quantity": "1",
"inventory_id": "82",
"individual_price": "2.90",
"batch_no": "",
如何轉換0在上述文本到字符串(「0 「)?
你寫出文字JSON字符串,這樣就把周圍的0引號? –
您的整個包含數據類型是一個字符串。你在第二個街區展示的「對象」在哪裏?是直接來自'ItemsAsJson()'函數嗎? – axlj
另一種方法是做這個答案中的建議。讓開發JSON序列化程序的人員定義正確的JSON語法。 https://stackoverflow.com/questions/1056121/how-to-create-json-string-in-c-sharp – axlj