What's the best way to loop through a JSON of

2019-03-01 13:47发布

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.

标签: unity3d
1条回答
【Aperson】
2楼-- · 2019-03-01 14:26

These days

JSON is BUILT IN to Unity.

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

it's that easy.

This raises a really important point. A HUGE point of confusion with Unity is that you get a lot of really old example code on the www. Because many new hobbyist programmers use Unity - and that's great, welcome! - you often get really incredible confusion with Unity. Here's just three random examples...

  • a long, long, long time ago you used to be able to use "unityscript" (something like "javascript") with Unity. Now you cannot, it's simply c# (which is far easier). But you still get 10000s of QA with beginners asking why "unityscript" doesn't work.

  • in truly ancient history Unity had a crappy "UI" system. It now has a superb UI system (it's called ... wait for it ... ".UI"). But you still get many questions (although finally less every month now) of people asking about the (amazingly complex) "ancient" system for ui, which you can't use any more.

  • in Unity, basically because Unity fucked-up at first, you had to use pooling (ie, - write your own pooling in a game engine. No, really.) for things like bullets. This is now ancient history, but you still get many people asking bizarre questions about the subtlety of pooling in unity (answer - you haven't had to do that for years - go drinking!)

  • millions - possibly a hundred million of man-hours (I did a calculation) have been spent by beginners trying to work out how to do timers in Unity. Unity called the timer in Unity "Invoke" (no, really) rather than - let's take a wild guess here - "Timer".

So anyway - it is very important to realize that

JSON is BUILT IN to Unity.

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

be very careful about incredibly out of date references to HandyJSON, SuperJSON, MegaJSON, JSONFinallyWithLessBugs, WhoaICanUseJSON and other totally shit packages. Just click here and enjoy:

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

Did I mention

JSON is BUILT IN to Unity these days.

Enjoy!

查看更多
登录 后发表回答