原文内容来自:Read from and write to external .json files using JsonUtilities or LitJson
文件Unity 版本号5.3,使用时候Unity 版本号5.6
本文仅作分析,学习用途。
_4Update_ObjectArray_LitJson
----------------------------------------------------------------------------------------------原代码+注释
// Reading an array with nested object stored in a JSON-formatted text file. Changing objects and adding more objects
// using LitJson
// At start: {"highscore":[{"name":"BadBoy","scores":4711}]}
// After step 5: {"highscore":[{"name":"BadBoy","scores":4712},{"name":"MadMax","scores":1234}]}
using UnityEngine;
using LitJson;
using System.IO;
using System.Collections.Generic;
public class _4Update_ObjectArray_LitJson : MonoBehaviour {
void Start () {
/**
* 1. Fetch text from file 从文件中取出 text 文本
*/
string jsonString = File.ReadAllText (Application.dataPath + "/Resources/Json_UpdateObjectArray.json");
Debug.Log ("JSON-String before: " + jsonString);
// logs {"highscore":[{"name":"BadBoy","scores":4711}]}
/**
* 2. Transform JSON formatted text into object
* 转换 JSON 格式 文本 成为 JSONDATA 对象 myObject
*/
JsonData myObject