You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a newbie. I am doing an Android web application, the code for parsing the json file is as follows
{
"name":"HelloWorld",
"description":"Simple web example application to demonstrate",
"package":"com.example.helloworld",
"version":"0.1.0",
"start_url":"index.html",
"icons":[
{
"src":"res/img/appicon.png"
}
],
"developer":{
"name":"Example Developer",
"url":"http://www.example.com/",
"email":"[email protected]"
}
}
and my cpp code is as follows
I want to know how to read the string of "icons". When i use j["icons"] or j["developer"], my web app has crashed. j["developer"]["name"] and j["name"] are no problem.
The text was updated successfully, but these errors were encountered:
The icons and developer entries aren't strings. The first is an array, and the second is an object. You can't convert them to a string like that. If you really do want the full JSON content of that entry as a string, you can use j["icons"].dump(), which will give you a string like this:
I am a newbie. I am doing an Android web application, the code for parsing the json file is as follows
{
"name":"HelloWorld",
"description":"Simple web example application to demonstrate",
"package":"com.example.helloworld",
"version":"0.1.0",
"start_url":"index.html",
"icons":[
{
"src":"res/img/appicon.png"
}
],
"developer":{
"name":"Example Developer",
"url":"http://www.example.com/",
"email":"[email protected]"
}
}
and my cpp code is as follows
std::string showJson(std::string cni, std::string cnj){
using json = nlohmann::json;
std::ifstream fin("/data/data/iecas.jsonshow.commanager/lib/manifest.json");
if(!fin) return "fin==null";
json j;
fin >> j;
fin.close();
if(cni == "name"&&cnj==" ") return j["name"];
if(cni == "description"&&cnj==" ") return j["description"];
if(cni == "package"&&cnj==" ") return j["package"];
if(cni == "version"&&cnj==" ") return j["version"];
if(cni == "start_url"&&cnj==" ") return j["start_url"];
if(cni == "developer"&&cnj=="name") return j["developer"]["name"];
if(cni == "developer"&&cnj=="url") return j["developer"]["url"];
if(cni == "developer"&&cnj=="email") return j["developer"]["email"];
if(cni == "developer"&&cnj==" ") return j["developer"];
if(cni == "icons"&&cnj==" ") return j["icons"];
}
I want to know how to read the string of "icons". When i use j["icons"] or j["developer"], my web app has crashed. j["developer"]["name"] and j["name"] are no problem.
The text was updated successfully, but these errors were encountered: