Create class User First
using System;
namespace JsonTest
{
public class User
{
public string name;
public string addr;
public string phoneNo;
public User ()
{
}
}
}
Than in main function
public static void Main (string[] args)
{
User me = new User ();
me.addr = "Taipei";
me.name = "peichun";
me.phoneNo ="123456789";
string jsonString = JsonConvert.SerializeObject (me);
Console.WriteLine (jsonString);
User you = JsonConvert.DeserializeObject(jsonString);
Console.WriteLine ("Second me : " + you.name);
}
No comments:
Post a Comment