链接获取Json字符串后遍历
来源:互联网 发布:电子小报制作软件 编辑:程序博客网 时间:2024/06/08 19:21
package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Test {
public static void main(String[] args) {
branchProfit();
}
public static String loadJSON (String url) {
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(),"UTF-8"));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
}
public static void branchProfit(){
String platform = loadJSON("http://192.168.100.3:8080/api/agentinfo/getFinanceInfo.html?id=562");
String merchant = loadJSON("http://192.168.100.3:8080/api/merchantinfo/getFinanceInfo.html?id=100464");
JSONObject dev=JSONObject.fromObject(platform);
JSONArray array=JSONArray.fromObject(dev.get("data"));//获取json对象的data
JSONObject obj=JSONObject.fromObject(array.get(0));//获取json数组的第一个
JSONArray dArray = (JSONArray) obj.get("data");
for (int i = 0; i < dArray.size(); i++) {
JSONObject jsonObj = dArray.getJSONObject(i);
System.out.println(jsonObj.get("agentAlipayName"));
System.out.println(jsonObj.get("agentName"));
System.out.println(jsonObj.get("agentId"));
System.out.println(jsonObj.get("agentPayOdd"));
System.out.println(jsonObj.get("agentCouponsOdd"));
System.out.println(jsonObj.get("agentAlipay"));
}
System.out.println(dArray);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Test {
public static void main(String[] args) {
branchProfit();
}
public static String loadJSON (String url) {
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(),"UTF-8"));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
}
public static void branchProfit(){
String platform = loadJSON("http://192.168.100.3:8080/api/agentinfo/getFinanceInfo.html?id=562");
String merchant = loadJSON("http://192.168.100.3:8080/api/merchantinfo/getFinanceInfo.html?id=100464");
JSONObject dev=JSONObject.fromObject(platform);
JSONArray array=JSONArray.fromObject(dev.get("data"));//获取json对象的data
JSONObject obj=JSONObject.fromObject(array.get(0));//获取json数组的第一个
JSONArray dArray = (JSONArray) obj.get("data");
for (int i = 0; i < dArray.size(); i++) {
JSONObject jsonObj = dArray.getJSONObject(i);
System.out.println(jsonObj.get("agentAlipayName"));
System.out.println(jsonObj.get("agentName"));
System.out.println(jsonObj.get("agentId"));
System.out.println(jsonObj.get("agentPayOdd"));
System.out.println(jsonObj.get("agentCouponsOdd"));
System.out.println(jsonObj.get("agentAlipay"));
}
System.out.println(dArray);
}
}
0 0
- 链接获取Json字符串后遍历
- JAVA遍历json字符串
- json遍历获取KEY
- Ext获取JSON字符串后赋值给联动下拉框
- jquery如何遍历json字符串
- 遍历JSON字符串转为HashMap
- Store获取json字符串
- 获取json字符串内容
- angular 获取json字符串
- 遍历JSON、获取JSON长度的方法
- 获取数据库的链接字符串
- 使用jqgrid从后台获取List后得到list的json字符串
- 从网址获取json字符串
- JQuery遍历JSON字符串 $.each实例
- JS遍历Json字符串中键值对
- JQuery遍历JSON字符串 $.each实例
- java 字符串转成 json 数组并且遍历
- 反序列化JSON字符串 &遍历JObject
- C/C++中指针所能指向的地址范围
- hdu 5112 (2014北京 水)
- Android源码开发之获取当前时间的时分秒
- 交换两个数的值,不借助第三方变量.
- 黑马程序员----Objective-C学习笔记之@class与循环retain问题
- 链接获取Json字符串后遍历
- 学习网站
- HDU 1950 Bridging signals(LIS)
- 百度2016研发工程师在线编程题
- android studio 编译出错 非法字符 未结束的字符
- ubuntu15.04手动安装MySQL5.6.27数据库
- hdu 5113(2014北京—搜索+剪枝)
- Java面向对象(一)
- 2034人见人爱A-B