java 解析json
例《解析评论》
//post方式请求
String url=“http://product.dangdang.com/comment/comment.php?product_id=60569472&datatype=1&page=1&filtertype=1&sysfilter=1&sorttype=1”;
//请求后的json格式

HttpPost httpPost=new HttpPost(url);
HttpClient defaultHttpClient= new DefaultHttpClient();
HttpResponse response = defaultHttpClient.execute(httpPost);
//请求状态吗
int StatusCode=response.getStatusLine().getStatusCode();
if(StatusCode==200){//状态码200表示成功
String result = EntityUtils.toString(response.getEntity());
JSONObject jsonObj = JSONObject.fromObject(result);
//取到key
int error_status = jsonObj.getInt("error_status");//请求状态如果==0
String error_string=jsonObj.getString("error_string");//如果==Succeed表示成功
if(error_status==0&error_string.equals("Succeed")){
//解析json数组
//评论内容
JSONArray jsonArray=jsonObj.getJSONArray("data");
int iSize = jsonArray.size();
for(int i=0;i<iSize;i++){
ipage=pageii;//记录异常出现使用
JSONObject jso = jsonArray.getJSONObject(i);
//去到相对应的key
product_id=jso.getInt("product_id");
String uname=jso.getString("cust_name");
String content=jso.getString("content");
String creation_date=jso.getString("creation_date");
int review_id=jso.getInt("review_id");
}
}
}
遇到问题:这错误原因是commons-lang.jar包版本问题
我项目中是commons-lang3-3.2.1.jar改成commons-lang-2.6.jar就没问题了
包下载地址:http://pan.baidu.com/s/1pJE3sbL

java 解析json的更多相关文章
- Java解析json字符串和json数组
Java解析json字符串和json数组 public static Map<String, String> getUploadTransactions(String json){ Map ...
- java解析Json字符串之懒人大法
面对Java解析Json字符串的需求,有很多开源工具供我们选择,如google的Gson.阿里巴巴的fastJson.在网上能找到大量的文章讲解这些工具的使用方法.我也是参考这些文章封装了自己的Jso ...
- Introduction to Structured Data json的2种形式 JAVA解析JSON数据 - JsonArray JsonObject
https://developers.google.com/search/docs/guides/intro-structured-data Structured data refers to kin ...
- java解析json数组
java解析json数组 import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; ...
- Java解析json(二):jackson
Java解析json(二):jackson 官方参考 Jackson Home Page:https://github.com/FasterXML/jackson Jackson Wiki:htt ...
- Java解析JSON文件的方法
http://blog.sina.com.cn/s/blog_628cc2b70101dydc.html java读取文件的方法 http://www.cnblogs.com/lovebread/ar ...
- java解析json
1:下载另外一个Java的小包就可以了: http://www.JSON.org/java/json_simple.zip 里面有源码和文档例题和编程的lib包:编程只需要json_simple.ja ...
- java 解析json的问题
本文转载自http://chriszz.sinaapp.com/?p=392 Json就是Javascript notation,可以替代XML,用做数据交互. Json的两种基本表示形式,可以用自动 ...
- java 解析json字符串
如果转载我的这篇文章请注明出处,谢谢! 最近工作中,需要解析json格式的字符串,恰好有个例子,感觉不错,拿来分享. 运行这个类需要加载jar包:ezmorph-1.0.6.jar.json-lib- ...
- java解析json字符串详解(两种方法)
一.使用JSONObject来解析JSON数据官方提供的,所以不需要导入第三方jar包:直接上代码,如下 private void parseJSONWithJSONObject(String Jso ...
随机推荐
- IOS9提示“不受信任的开发者”如何处理
iPhone升级到IOS9版本后,发现部分APP在下载后首次运行时,都会提示“不受信任的应用程序开发者”,这是因为企业证书发布的APP,没有经过AppStore审核,于是iOS对用户做出一个安全性的提 ...
- 步进控件——UIStepper
步进控件,可用于替换传统用于输入值的文本框.步进控件提供了“+”和“-”两个按钮,用来改变stepper内部value的增加或减少,调用的事件是UIControlEventValueChanged.由 ...
- Spark Standalone Mode
It is very easy to install a Spark cluster (Standalone mode). In my example, I used three machines. ...
- SVN打基线
分成trunk.tags.branches的话,那直接从trunk copy 到tags下面就可以或者按照你自己的目录,只要规定好就行 选择要打基线的项目的根目录,右击鼠标,在弹出的菜单中选择“分支/ ...
- error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier
xcode + iwatch调试错误 在工程的 Targets 下面的 三项(工程名为my):my . my Watchkit app .my Watchkit extention General ...
- Repeated Substring Pattern Leetcode
Given a non-empty string check if it can be constructed by taking a substring of it and appending mu ...
- --@angularJS--独立作用域scope绑定策略之&符策略
1.index.html: <!DOCTYPE HTML><html ng-app="app"><head> <title>s ...
- Could not execute auto check for display colors using command /usr/bin/xdpyinfo.(
Steps to resolve this issue: 1) login into root user( su -l root) 2) execute this command : xhost +S ...
- jQuery基本过滤选择器
jQuery基本过滤选择器: <h1>this is h1</h1> <div id="p1"> <h2>this is h2< ...
- Valgrind使用记录
0.安装valgrind wget http://valgrind.org/downloads/valgrind-3.11.0.tar.bz2 tar xvf valgrind-3.11.0.tar. ...