本文介绍了循环遍历销售数据的 JSON 以在 Unity 中创建图表的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 this 教程来帮助我在 Unity 中制作图形,但是我想要基于包含销售数据的 JSON 创建其中的数据点.你们怎么建议我这样做?我还在学习,所以任何帮助都会非常有帮助.

I used this tutorial to help me make graphs in Unity, however I want the data points in it to be created based on a JSON that contains sales data. How would you guys advise I do that? I am still learning, so any help would be extremely helpful.

推荐答案

这些天

https://docs.unity3d.com/Manual/JSONSerialization.html

就这么简单.

与 Unity 混淆的一个重要原因是您在网络上获得了很多非常旧的示例代码.

A HUGE cause of confusion with Unity is that you get a lot of really old example code on the web.

  • 10 多年前,您可以在 Unity 中使用 C# 以外的语言.现在只有C#.但是您仍然会收到 1000 多个问题,询问为什么 javascript 等不起作用!

  • Ten+ years ago you could use languages other than C# with Unity. Nowadays it is only C#. But you still get 1000s of questions asking why javascript, etc, doesn't work!

十多年前,Unity 有一个蹩脚的UI"系统.它现在有一个极好的 UI 系统(它被称为.UI").但是你仍然对荒谬的早期 UI 系统有很多疑问.

Ten+ years ago Unity had a crappy "UI" system. It now has a superb UI system (it's called ".UI"). But you still get many questions about the ridiculous early-days UI system.

在古老的 Unity 中,即使在最简单的情况下(例如子弹),您也必须使用池化.现在 Unity 大大提高了性能,在正常游戏情况下完全不需要池化.

In ancient Unity, you had to use pooling in even the simplest cases, say for bullets. Unity nowadays vastly improved performance and pooling is totally unnecessary in normal game situations.

出于某种原因,Unity 将简单计时器命名为Invoke"而不是定时器"- 这导致了 1000 多个问题!

For some reason Unity named the simple timer "Invoke" rather than "Timer" - this has led to 1000s of questions!

注意对 HandyJSON、SuperJSON、MegaJSON、JSONFinallyWithLessBugs、WhoaICanUseJSON 和其他垃圾包的过时引用.

Be careful of incredibly out-of-date references to HandyJSON, SuperJSON, MegaJSON, JSONFinallyWithLessBugs, WhoaICanUseJSON and other rubbish packages.

这是一个从文本文件解析一些 Json 的简单示例,在本例中将其放入字典:

Here is a simple example of parsing some Json from a text file, and in this case putting it into a Dictionary:

using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;

public class JsonTexts : MonoBehaviour
{
    public TextAsset ta; // drag to link in Editor
    [NonSerialized] public Dictionary<string, JsonParsePerson> persons;

    [Serializable]
    public class JsonParsePerson
    {
        public string id;
        public string firstname;
        public string lastname;
    }

    [Serializable]
    public class JsonParsePersons
    {
        public JsonParsePerson[] persons;
    }

    void Start()
    {
        JsonParsePersons pp = JsonUtility.FromJson<JsonParsePersons>(ta.text);
        persons = pp.persons.ToDictionary(i => i.id, i => i);

        // foreach (JsonParsePerson p in pp.persons)
        //   { Debug.Log($"it worked {p.id} {p.firstname}"); }
    }
}

这篇关于循环遍历销售数据的 JSON 以在 Unity 中创建图表的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 08:42