- 博客(0)
- 资源 (3)
- 收藏
- 关注
C# JSON 编码解码
//Program.cs 里是一些比较极端的测试,实际使用时只需复制 JSON.cs 到项目里。
//比如类Vec2:
public class Vec2
{
public float x;
public float y;
}
//编码范例:
Vec2 v1 = new Vec2();
v1.x = 1.23f;
v1.y = 4.56f;
string jsonCode = JSON.Encode(v1);
Console.WriteLine("jsonCode=" + jsonCode);
//jsonCode 为格式化好的JSON字符串:
{
"x":1.23,
"y":4.56
}
//解码范例:
Vec2 v2 = JSON.Decode(jsonCode);
Console.WriteLine("v2.x=" + v2.x + ",v2.y=" + v2.y);
2016-09-07
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人