1.JSON抓取文件解析文件

package com.xiaoyan;

import java.awt.Window.Type;
import java.io.FileNotFoundException;
import java.io.FileReader;

import org.json.JSONObject;

public class Zhuaqu {
    public static void main(String[] args) {
        //读取解析account文件
        String strFileName="D:/mail/account/account.JSON";
        
        try {
            FileReader ac = new FileReader(strFileName);
              char[] a=new char[1024];
               String str="";
               
               int i=0;
                
               while((i=ac.read(a))>0)
                 {
                     str+=new String(a,0,i);
                 }
               System.out.println(str);
               JSONObject jo = new JSONObject(str);
               JSONObject account =jo.getJSONObject("account");
               System.out.println("邮箱登陆账号"+jo.getJSONObject("account").getString("username"));
               System.out.println("邮箱登陆密码"+jo.getJSONObject("account").getString("password"));
             
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }

}

 

posted @ 2016-08-11 08:55  薛岩  阅读(433)  评论(0编辑  收藏  举报