java jettison_org.codehaus.jettison.json.JSONObject使用方法

java jettison_org.codehaus.jettison.json.JSONObject使用方法publicstatic String args System out println 测试开始 Filefile newFile D files req txt BufferedRead null StringjsonSt try reader newBufferedR newFileRead

public static void main(String[] args)

{

System.out.println(“测试开始”);

File file = new File(“D:/files/req.txt”);

BufferedReader reader = null;

String jsonStr = “”;

try

{

reader = new BufferedReader(new FileReader(file));

String readLine = “”;

while ((readLine = reader.readLine()) != null)

{

jsonStr += readLine + “\n”;

}

System.out.println(jsonStr);

JSONObject jsonObj;

try

{

jsonObj = new JSONObject(jsonStr);

System.out.println(jsonObj.get(“Version”));

System.out.println(jsonObj.get(“VimId”));

}

catch (JSONException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

}

catch (FileNotFoundException e)

{

e.printStackTrace();

System.out.println(“e” + e.getMessage());

}

catch (IOException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

System.out.println(“error” + e.getMessage());

}

finally

{

if (reader != null)

{

try

{

reader.close();

}

catch (IOException e)

{

System.out.println(“close fail!!”+ e.getMessage());

}

}

}

}

输出结果:

测试开始

{

“Version”: “1.0”,

“VimId”: “81f1d9d0-ca13-4eea-a4ce-9bd89a50c9d1”,

“SrcType”: “vpim”,

“MsgType”: “vimPmMetrics”,

“FileUri”: “https://192.168.112.80:9131/v1/vimPm/files/5.gz”

}

1.0

81f1d9d0-ca13-4eea-a4ce-9bd89a50c9d1

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/212051.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 下午8:57
下一篇 2026年3月18日 下午8:57


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号