android解析json数据
来源:互联网 发布:宣传手册制作软件 编辑:程序博客网 时间:2024/04/28 23:47
项目中要用到json数据格式,偷闲写了个demo出来,数据是从txt文件中读取的。
代码就两段:
json解析方法
public void json2Str(String src) throws JSONException{
JSONObject jsonObject = new JSONObject(src);
String id;
String sendName;
String sendTime;
String title;
String source;
String url;
String postTime;
String content;
id = jsonObject.getString("id");
sendName = jsonObject.getString("senderName");
sendTime = jsonObject.getString("sendTime");
title = jsonObject.getString("title");
source = jsonObject.getString("source");
url = jsonObject.getString("url");
postTime = jsonObject.getString("posttime");
content = jsonObject.getString("content");
txt.setText(":" + id + "\n" + ":" + sendName + "\n" + ":" + sendTime + "\n" + ":" + title
+ "\n" + ":" + source + "\n" + ":" + url + "\n" + ":" + postTime
+ "\n" + ":" + content);
}
读取txt文件:
String src = null;
InputStream in;
try{
in = getResources().openRawResource(R.raw.json);
int length = in.available();
byte [] buffer = new byte[length];
in.read(buffer);
src = EncodingUtils.getString(buffer, "GBK");
in.close();
}
catch (Exception e){
e.printStackTrace();
}
etx.setText("已加载内容");
try {
json2Str(src);
} catch (JSONException e) {
e.printStackTrace();
}
- android---Json数据解析
- Android Json 数据解析
- Android解析json数据
- android解析json数据
- Android-解析json数据
- Android Json数据解析
- Android解析JSON数据
- Android解析Json数据
- Android json数据解析
- android解析json数据
- android解析JSON数据
- Android解析json数据
- android Json数据解析
- android JSON数据解析
- Android 解析 Json 数据
- Android JSON数据解析
- Android JSON数据解析
- Android json数据解析
- 什么叫黑链-SEO zuobi手法解析
- 关于补码
- android.view.View---中文
- UIView如何管理它的子视图
- c# 的 sting.empty 与 javascript 中的""
- android解析json数据
- 处理jquery版本之间冲突
- textview在多行情况下如何显示省略号
- 流程控制
- 更改可执行文件的输出路径方法
- java根据时间生成唯一ID
- CodeBlocks在win7+VS2010下的配置
- 数组Array
- 测试高亮,测试之用