小编abh*_*hek的帖子

统一读取和解析 C# 中的 Json 文件

这是代码

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

public class csharpfile:MonoBehaviour{

    public void LoadJson()
    {
        using (StreamReader r = new StreamReader("file.json"))
        {
            string json = r.ReadToEnd();
            List<Item> items = JsonConvert.DeserializeObject<List<Item>>(json);


        }
    }

    public class Item
    {
        public int millis;
        public string stamp;
        public DateTime datetime;
        public string light;
        public float temp;
        public float vcc;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我想解析文件内容(file.json)

[ 
    { "millis": "1000", 
      "stamp": "1273010254", 
      "datetime": "2010/5/4 21:57:34", 
      "light": "333", 
      "temp": "78.32", 
      "vcc": "3.54" }, 
] 
Run Code Online (Sandbox Code Playgroud)

文件解析后我将如何在屏幕上打印内容以及如何写入文件 .do help …

c# json unity-game-engine jsonobject

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

json ×1

jsonobject ×1

unity-game-engine ×1