public class userInfo
{
public string customerName { get; set; }
public string sex { get; set; }
public string age { get; set; }
public string time { get; set; }
public string quality { get; set; }
public string siteName { get; set; }
}
public class AllO
{
public string name { get; set; }
public userInfo userInfo { get; set; }
public string date { get; set; }
}
class GenericMethod
{
public static T show<T>(T obj, string tParameter)
{
T jsonObj = JsonConvert.DeserializeObject<T>(tParameter);
return jsonObj;
}
public static void save<T>(T tParameter)
{
string output = Newtonsoft.Json.JsonConvert.SerializeObject(tParameter, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(Application.StartupPath + @"\data3.json", output);
}
}
private void button19_Click(object sender, EventArgs e)
{
try
{
string path = Application.StartupPath + @"\data.json";
StreamReader streamReader = new StreamReader(path);
string jsonStr = streamReader.ReadToEnd();
AllO jsonObj = GenericMethod.show<AllO>(new AllO(), jsonStr);
GenericMethod.save<AllO>(jsonObj);
streamReader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "/r/n" + ex.StackTrace);
}
}
{
"name": "99999",
"userInfo": {
"customerName": "123456",
"sex": "男",
"age": "49",
"time": "2017-01-18 10:30 巳时",
"quality": "86.5",
"siteName": "医疗机构/健康会所"
},
"date": "2020-01-02"
}