Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:解析JSON文件_Java_String_Json - Fatal编程技术网

Java:解析JSON文件

Java:解析JSON文件,java,string,json,Java,String,Json,我有一个类似这样的Json文件 {"Name":"Saaa","AppIcon":["ddd.jpg","Wallpaper.jpg","ddd.jpg"]} 我需要提取AppIcon值。我正在使用jsonsimplelib解析json。要分析这些值的代码段是: FileReader appIconReader = new FileReader("jsonpath.json"); JSONObject jsonIconObject = (JSONObject)jsonParser.parse(

我有一个类似这样的Json文件

{"Name":"Saaa","AppIcon":["ddd.jpg","Wallpaper.jpg","ddd.jpg"]}
我需要提取
AppIcon
值。我正在使用
jsonsimple
lib解析
json
。要分析这些值的代码段是:

FileReader appIconReader = new FileReader("jsonpath.json");
JSONObject jsonIconObject = (JSONObject)jsonParser.parse(appIconReader);
System.out.println("APPLICATION ICON = "+jsonIconObject.get("AppIcon"));`
但是我得到的输出是一个字符串:

["ddd.jpg","Wallpaper.jpg","ddd.jpg"]
我需要像这样提取单个值

ddd.jpg
Wallpaper.jpg
ddd.jpg
不是用方括号([])和双引号(“”),正如我现在得到的。我该怎么做呢?

的文档不是很完整,但是如果您想处理数组,需要强制转换
返回的对象。get()

JSONArray
似乎是可以迭代的通用容器,例如:

Iterator<String> it = appIcon.iterator();
while (it.hasNext()) System.out.println(it.next());
Iterator it=appIcon.Iterator();
while(it.hasNext())System.out.println(it.next());
的文档不是很完整,但是如果要处理数组,需要强制转换
返回的对象。get()

JSONArray
似乎是可以迭代的通用容器,例如:

Iterator<String> it = appIcon.iterator();
while (it.hasNext()) System.out.println(it.next());
Iterator it=appIcon.Iterator();
while(it.hasNext())System.out.println(it.next());
的文档不是很完整,但是如果要处理数组,需要强制转换
返回的对象。get()

JSONArray
似乎是可以迭代的通用容器,例如:

Iterator<String> it = appIcon.iterator();
while (it.hasNext()) System.out.println(it.next());
Iterator it=appIcon.Iterator();
while(it.hasNext())System.out.println(it.next());
的文档不是很完整,但是如果要处理数组,需要强制转换
返回的对象。get()

JSONArray
似乎是可以迭代的通用容器,例如:

Iterator<String> it = appIcon.iterator();
while (it.hasNext()) System.out.println(it.next());
Iterator it=appIcon.Iterator();
while(it.hasNext())System.out.println(it.next());

您也可以试试这个,它是列表类型中的存储值:

 try {
        FileReader appIconReader = new FileReader("jsonpath.json");
        JSONObject jsonIconObject = (JSONObject)jsonParser.parse(appIconReader);
        JSONArray lan = jsonIconObject.get("AppIcon"));
        List<String> list = new ArrayList<String>();
        for(int i = 0; i < arr.length(); i++){
            list.add(lan.getJSONObject(i).getString("name"));
        }

    } catch (org.json.simple.parser.ParseException e) {
        e.printStackTrace();
    }
试试看{
FileReader appIconReader=newFileReader(“jsonpath.json”);
JSONObject jsonIconObject=(JSONObject)jsonParser.parse(appIconReader);
JSONArray lan=jsonIconObject.get(“AppIcon”);
列表=新的ArrayList();
对于(int i=0;i
您也可以试试这个,它是列表类型中的存储值:

 try {
        FileReader appIconReader = new FileReader("jsonpath.json");
        JSONObject jsonIconObject = (JSONObject)jsonParser.parse(appIconReader);
        JSONArray lan = jsonIconObject.get("AppIcon"));
        List<String> list = new ArrayList<String>();
        for(int i = 0; i < arr.length(); i++){
            list.add(lan.getJSONObject(i).getString("name"));
        }

    } catch (org.json.simple.parser.ParseException e) {
        e.printStackTrace();
    }
试试看{
FileReader appIconReader=newFileReader(“jsonpath.json”);
JSONObject jsonIconObject=(JSONObject)jsonParser.parse(appIconReader);
JSONArray lan=jsonIconObject.get(“AppIcon”);
列表=新的ArrayList();
对于(int i=0;i
您也可以试试这个,它是列表类型中的存储值:

 try {
        FileReader appIconReader = new FileReader("jsonpath.json");
        JSONObject jsonIconObject = (JSONObject)jsonParser.parse(appIconReader);
        JSONArray lan = jsonIconObject.get("AppIcon"));
        List<String> list = new ArrayList<String>();
        for(int i = 0; i < arr.length(); i++){
            list.add(lan.getJSONObject(i).getString("name"));
        }

    } catch (org.json.simple.parser.ParseException e) {
        e.printStackTrace();
    }
试试看{
FileReader appIconReader=newFileReader(“jsonpath.json”);
JSONObject jsonIconObject=(JSONObject)jsonParser.parse(appIconReader);
JSONArray lan=jsonIconObject.get(“AppIcon”);
列表=新的ArrayList();
对于(int i=0;i
您也可以试试这个,它是列表类型中的存储值:

 try {
        FileReader appIconReader = new FileReader("jsonpath.json");
        JSONObject jsonIconObject = (JSONObject)jsonParser.parse(appIconReader);
        JSONArray lan = jsonIconObject.get("AppIcon"));
        List<String> list = new ArrayList<String>();
        for(int i = 0; i < arr.length(); i++){
            list.add(lan.getJSONObject(i).getString("name"));
        }

    } catch (org.json.simple.parser.ParseException e) {
        e.printStackTrace();
    }
试试看{
FileReader appIconReader=newFileReader(“jsonpath.json”);
JSONObject jsonIconObject=(JSONObject)jsonParser.parse(appIconReader);
JSONArray lan=jsonIconObject.get(“AppIcon”);
列表=新的ArrayList();
对于(int i=0;i
您在此处得到的答案可能重复。所以你在两个不同的网站上发布了相同的问题。这是无效的。请用您正在处理的确切JSON更新您的问题。@HotLicks:这是一个打字错误……我编辑了我的问题。这里可能有您的重复答案。所以你在两个不同的网站上发布了相同的问题。这是无效的。请用您正在处理的确切JSON更新您的问题。@HotLicks:这是一个打字错误……我编辑了我的问题。这里可能有您的重复答案。所以你在两个不同的网站上发布了相同的问题。这是无效的。请用您正在处理的确切JSON更新您的问题。@HotLicks:这是一个打字错误……我编辑了我的问题。这里可能有您的重复答案。所以你在两个不同的网站上发布了相同的问题。这是无效的。请用您正在处理的确切JSON更新您的问题。@HotLicks:那是一个打字错误……我编辑了我的问题。