- Home /
Closed :
Retreive Jsonfile and Read It
Could someone please explain me how this code works . Cause i'm going to implement this on my project . Please
LitJson.JsonData data = LitJson.JsonMapper.ToObject(json);
json = data[language.ToString()].ToJson();
notice = LitJson.JsonMapper.ToObject<string[]>(json);
I'm not pretty sure how it works. Am i correct on this one Explanation: I do a ToObject and assign it to the variable data and then converted it back to json and assign it to the json variable then try to convert it back to an object and create a generic string[] . Is that right? How can i correct this one . What i am doing is reading the .json file in my android and convert it to string.
What are you trying to do and what makes you think that block is what you need?
That code can be expanded a bit:
// Start with:
// some json object as a string, called "json",
// some other variable called "language", presumably also a string
// some other variable called "notice", an array of strings
//
// Convert the json string into a LitJson JSON object
LitJson.JsonData data = LitJson.Json$$anonymous$$apper.ToObject(json);
// Take the json sub-object mapped to whatever language is
// represented by this variable
string languageSubObject = data[language.ToString()].ToJson();
// convert this sub-object to an array of strings
notice = LitJson.Json$$anonymous$$apper.ToObject<string[]>(languageSubObject );
So this code is looking to get the value stored at whatever language
is, which seems to be an array of strings.
Hello Trey. Thank you for the explanation so i am correct basically. Now can i ask another question?
LitJson.JsonData data = LitJson.Json$$anonymous$$apper.ToObject(json);
json = data[language.ToString()].ToJson();
notice = LitJson.Json$$anonymous$$apper.ToObject<string[]>(json);
this doesn't work on android. Can you please help me out
Well, what do you mean by "doesn't work"? That will not run as is, since you have 3 variables that are undefined according to that scope (json, notice, and language).
I'm not familiar with LitJson, but this other question is also a problem with that library and android, specifying that the OP needed to use a different path for android builds. What error message are you getting? Does that work in the editor?
Follow this Question
Related Questions
WWW data acquisition from remote server failing 2 Answers
Problem Parsing Json (JsonUtility) 1 Answer
Integrating Watson Speech-to-Text with Unity 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers