{"sex":"male","time":"23-06-09","weight":"88.5","height":"176.0","order":"measure","bmi":"28.6","machine_ID":"19081000"} c# 转换成数据集,并取出身高体重
时间: 2023-07-08 13:55:32 浏览: 45
可以将这个JSON字符串转换成一个`Dictionary<string, string>`对象,然后将其添加到一个`DataTable`中,最后从`DataTable`中获取身高和体重的值。示例代码如下:
```csharp
using System;
using System.Collections.Generic;
using System.Data;
using Newtonsoft.Json;
class Program
{
static void Main(string[] args)
{
string json = "{\"sex\":\"male\",\"time\":\"23-06-09\",\"weight\":\"88.5\",\"height\":\"176.0\",\"order\":\"measure\",\"bmi\":\"28.6\",\"machine_ID\":\"19081000\"}";
Dictionary<string, string> dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
DataTable table = new DataTable();
foreach (string key in dict.Keys)
{
table.Columns.Add(key, typeof(string));
}
DataRow row = table.NewRow();
foreach (string key in dict.Keys)
{
row[key] = dict[key];
}
table.Rows.Add(row);
string weight = table.Rows[0]["weight"].ToString();
string height = table.Rows[0]["height"].ToString();
Console.WriteLine("Weight: " + weight);
Console.WriteLine("Height: " + height);
}
}
```
运行结果:
```
Weight: 88.5
Height: 176.0
```