org.codehaus.jettison.json.JSONObject使用方法
2024-10-21 14:38:28
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/201606011415.gz"
} 1.0
81f1d9d0-ca13-4eea-a4ce-9bd89a50c9d1
最新文章
- ASP.Net 在Update Panel局部刷新后 重新绑定JS方法
- Java多线程21:多线程下的其他组件之CyclicBarrier、Callable、Future和FutureTask
- 转:JavaScript中的this陷阱的最全收集
- JAVA导入包
- Saltstack系列5:Saltstack之pillar组件
- Write operations are not allowed in read-only mode (FlushMode.NEVER/
- 程序自动生成Dump文件
- C# 封装
- XP 右键扩展设置 1.0 免费绿色版
- xcode7中使用cocos2d-x3.8的webview控件
- Java版连连看
- 机器学习之正则化(Regularization)
- MySql中的约束
- tomcat启动失败问题总结
- 2018.3 江苏省计算机等级考试 C语言 编程题答案
- 安装Linux Mint17
- D05——C语言基础学PYTHON
- java中JVM的原理
- MySQL基础练习(二)
- Support for SSL/TLS protocols on Windows
热门文章
- firefox浏览器和IE
- Android — 长按ListView 利用上下文菜单(ActionMode) 进行批量事件处理
- Codeforces Round #422 (Div. 2) B. Crossword solving 枚举
- unity 3D Mesh网络模型,怎样将Constructer拖入场景??
- Thread Runnable 区别
- 使用JavaScript获取浏览器Chrome版本信息
- Linux Linker Script
- bzoj3090: Coci2009 [podjela]
- gunicorn启动django时静态文件的加载
- .NETFramework:Encoding