How to read JSON data from a web service in C#
C# Lesson, Intermediate, Tutorial, Unity
0
👍 How to read a JSON data from a web service in Unity. This Tutorial is about reading JSON data. We will build a little application build on a JSON webservice.
✅ Download the free SimpleJSON parser:
https://github.com/HenrikPoulsen/SimpleJSON
✅ The free geoplugin webservice:
http://www.geoplugin.net/json.gp?ip=213.22.22.98
❤️ Subscribe to Oxmond Tutorials. New tutorials every day! Stay tuned!
https://bit.ly/SubscribeOxmondTutorials
🔔 Remember to hit that little bell to turn on notifications!
✅ Download free assets from the Unity Assets Store for your game:
https://assetstore.unity.com/lists/top-free-packages-13201?aid=1100l4p9k
The LoadJSON script:
/* .-------. .--. .-------. .--. .--. .--. | |--.--.--------.-----.-----.--| | |_ _|--.--| |_.-----.----|__|---.-| |-----. | - |_ _| | _ | | _ | | | | | | _| _ | _| | _ | |__ --| |_______|__.__|__|__|__|_____|__|__|_____| |___| |_____|____|_____|__| |__|___._|__|_____| © 2019 OXMOND / www.oxmond.com */ using System.Collections; using UnityEngine; using SimpleJSON; using UnityEngine.Networking; using TMPro; public class LoadJSON : MonoBehaviour { public TMP_InputField inputTxt; public TMP_Text countryTxt; public TMP_Text continentTxt; public void GetJsonData() { StartCoroutine(RequestWebService()); } IEnumerator RequestWebService() { string getDataUrl = "http://www.geoplugin.net/json.gp?ip=" + inputTxt.text; print(getDataUrl); using (UnityWebRequest webData = UnityWebRequest.Get(getDataUrl)) { yield return webData.SendWebRequest(); if (webData.isNetworkError || webData.isHttpError) { print("---------------- ERROR ----------------"); print(webData.error); } else { if (webData.isDone) { JSONNode jsonData = JSON.Parse(System.Text.Encoding.UTF8.GetString(webData.downloadHandler.data)); if (jsonData == null) { print("---------------- NO DATA ----------------"); } else { print("---------------- JSON DATA ----------------"); print("jsonData.Count:" + jsonData.Count); countryTxt.text = jsonData["geoplugin_countryName"]; continentTxt.text = jsonData["geoplugin_continentName"]; } } } } } }
Tags In
2019
C#
coding pirates
example
file
get
Hans Oxmond
Henrik Poulsen
how
how to
How to get JSON data from a web service in Unity
How to read a JSON file in Unity
How to read JSON data from a web service in C#
import
Import JSON file
json
json file
json list
json object
json parser
jsonobject
jsonutility
learn
lesson
list
load
loading
Oxmond Unity Tutorials
parse
read
reading
service
simple
SimpleJSON
tip
tutorial
Unity
Unity3d
video games
web
Related Posts
Leave a Reply Cancel reply
Tags
2D (12)
3D (5)
2018 (13)
2019 (17)
animation (7)
beginner (6)
beginners (13)
Beginner Tutorial - Unity 2019 (5)
button (4)
C# (21)
change (8)
coding (17)
coding pirates (28)
collision (3)
color (4)
control (5)
development (24)
effect (5)
game (27)
game making (11)
gameobject (4)
gameplay (4)
Hans Oxmond (17)
how to (15)
intermediate (5)
learn (17)
lesson (29)
material (3)
mouse (6)
object (6)
Oxmond Unity Tutorials (20)
script (4)
scripting (10)
scripting 2d (3)
shader (4)
sprite (7)
sprites (5)
tip (15)
tricks (5)
tutorial (17)
tutorials (21)
Unity (32)
Unity3d (29)
unity 2019 (7)
video games (17)