C# Newtonsoft_JSON 如何循环取出KEY和VALUE
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private DataSet FDataSet;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string json = @"{'template':'aas.html','ver':'3','status':1,'Tables':{'order':[{'ordersn':'201708142112515991A1D35BD4A','money':'679.92'},{'ordersn':'201708132245505990661EE0971','money':'2976.23'}]},'detail':[{'ordersn':'201708142112515991A1D35BD4A','categoryname':'超白10mm','money':130},{'ordersn':'201708142112515991A1D35BD4A','categoryname':'超白10mm','width':'670','money':23.2},{'ordersn':'201708142112515991A1D35BD4A','categoryname':'普玻15mm','money':374.77}]}";
JObject jsonObj = (JObject.Parse(json));
Console.WriteLine(jsonObj.Count);
FDataSet = new DataSet();
foreach (var item in jsonObj["Tables"])
{
foreach (var data in item)
{
//这里如何取得Key和Value
foreach (var s in data) {
//这里如何取得Key和Value
}
}
}
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private DataSet FDataSet;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string json = @"{'template':'aas.html','ver':'3','status':1,'Tables':{'order':[{'ordersn':'201708142112515991A1D35BD4A','money':'679.92'},{'ordersn':'201708132245505990661EE0971','money':'2976.23'}]},'detail':[{'ordersn':'201708142112515991A1D35BD4A','categoryname':'超白10mm','money':130},{'ordersn':'201708142112515991A1D35BD4A','categoryname':'超白10mm','width':'670','money':23.2},{'ordersn':'201708142112515991A1D35BD4A','categoryname':'普玻15mm','money':374.77}]}";
JObject jsonObj = (JObject.Parse(json));
Console.WriteLine(jsonObj.Count);
FDataSet = new DataSet();
foreach (var item in jsonObj["Tables"])
{
foreach (var data in item)
{
//这里如何取得Key和Value
foreach (var s in data) {
//这里如何取得Key和Value
}
}
}
}
}
} 展开
2个回答
展开全部
SortedList<string, string> STK = new SortedList<string, string>();
STK.Add("1", "2");
STK.Add("3", "4");
foreach (KeyValuePair<string,string> item in STK)
{
Console.Write(string.Format("{0}:{1}",item.Key,item.Value));
}
STK.Add("1", "2");
STK.Add("3", "4");
foreach (KeyValuePair<string,string> item in STK)
{
Console.Write(string.Format("{0}:{1}",item.Key,item.Value));
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询