using UnityEngine;
using System.Collections;
using System.Json;
public class MyJson : MonoBehaviour {
// Use this for initialization
void Start () {
//定义一个Json对象
JsonObject json_tranform = new JsonObject ();
//定义一个Json值
JsonValue json_position = "192.168.1.1";
//将Json值添加到Json对象中
json_tranform.Add ("position", json_position);
Debug.Log (json_tranform);
//把一个JsonValue数组添加到对应的key中
JsonValue[] json_rotations = new JsonValue[]{ 1, 2, 3 };
JsonArray array_rotation = new JsonArray (json_rotations);
json_tranform.Add ("rotation", array_rotation);
Debug.Log (json_tranform);
//把3个Json对象添加到数组中,并与key为scale相关联
JsonObject x = new JsonObject ();
x.Add ("x", 123);
JsonObject y = new JsonObject ();
y.Add ("x", 456);
JsonObject z = new JsonObject ();
z.Add ("x", 789);
JsonValue[] xyz = new JsonValue[]{ x, y, z };
JsonArray aaa = new JsonArray (xyz);
json_tranform.Add ("scale", aaa);
Debug.Log (json_tranform);
}
// Update is called once per frame
void Update () {
}
}
数据储存Json
最新推荐文章于 2024-08-01 20:08:52 发布