Hi, i would like to get some help on how to convert convert webRequest.downloadHandler.text to an array so i can use the values inside the array to generate terrain.
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Webadas : MonoBehaviour
{
public GameObject Example;
public double lat;
public double lon;
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
switch (webRequest.result)
{
case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError:
Debug.LogError(pages[page] + ": Error: " + webRequest.error);
break;
case UnityWebRequest.Result.ProtocolError:
Debug.LogError(pages[page] + ": HTTP Error: " + webRequest.error);
break;
case UnityWebRequest.Result.Success:
Debug.Log(webRequest.downloadHandler.text);
break;
}
}
}
void Update()
{
if (Input.GetKeyDown("f"))
{
String url =
"http://34gre54y45y5y4.pythonanywhere.com/req?lat=" + lat + "&lon=" + lon +
"&scale=128&res=128&=0.087890625&2=0.06638549349256095&zoom=15";
// A correct website page.
StartCoroutine(GetRequest(url));
}
}
}
I just had a look at your data (with a random lat / lon) and it actually is json. It’s an object that contains two fields. One is called “Bing” which is a long array (16k+) of 3 digit integer values and another field called “Colors” which is an even longer array (49k+) of arrays with 3 integer values which look like 8bit RGB values. Unity has the JSONUtility which can read and write simple json objects. However it does not support nested arrays. So you have to use another json library like (newtonsoft’s) Json.Net library or my SimpleJSON library (probably with the Unity extension file which allows to directly convert your nested array to a Color).
Anyways you would need some code to extract and convert the relevant data into whatever array(s) you need inside your code. We don’t even know for sure what that data should represent so that’s all up to you. So if you need further help you should provide more information. If that API you’re using is not your own, you may read the documentation or contact the owner of that API service for advice. If it’s your own API you should already know what your data represent and how it’s structured.