0

Needing help with a json (LitJson) issue. I am trying to read a json file from the web in the same way as I am able to read a local json file.

the way I read the local file is like this

public JsonData itemData;
itemData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/StreamingAssets/Art_.json"));

when I debug itemData I get back JsonData array in the console.

I am successfully reading the json file from the web with this:

UnityWebRequest webjson = UnityWebRequest.Get("http://somewebsite.com/Art_.json");

when I debug webjson i get back the entire json file in the console.

I am not sure how the json is being parsed differently, and why I can not replace the locally served json data with the json data being served from the url.

Thank you for any and all help.

cyo
  • 69
  • 1
  • 14
  • I cast like this: `var jsonweb = webjson; itemData = JsonMapper.ToJson(jsonweb); Debug.Log(itemData);` And now I am getting back the Json data in the console but with many other pieces of information and numbers, and then the Json at the end. – cyo Dec 30 '19 at 00:23
  • Well at least now you know why it wasnt working. Whats the other information – BugFinder Dec 30 '19 at 01:02
  • So, it is possible that i need to use `Trim()` to trim the json file. If I do `itemData = JsonMapper.ToObject(webjson.downloadHandler.text.Trim());` I receive the error `JsonException: Invalid character '' in input string` – cyo Dec 30 '19 at 02:35
  • You’d need to show the data you’re getting back for anyone to answer – BugFinder Dec 30 '19 at 05:58
  • at the moment I get no data back if I use ` itemData = JsonMapper.ToObject(webjson.downloadHandler.text.Trim());` – cyo Dec 30 '19 at 06:01
  • I get the same error, `JsonException: Invalid character '' in input string` – cyo Dec 30 '19 at 06:02
  • As I said you need to show us the whole text you are getting back in that string.. – BugFinder Dec 30 '19 at 12:39

0 Answers0