您的位置:首页 > Web前端 > JavaScript

String转换为JSON以及时间的格式化

2015-07-14 21:22 736 查看
<pre name="code" class="java"><span style="font-family:Microsoft YaHei;">public Map DnsQueryThird (String ipString )
{
     Map map = createDwrMap();
    
    String ADD_URL = "http://out.dns.dnion.com:53053/dnsout?domain=";
//  String ADD_URL = "http://interface.dns.dnion.com/getdnsip";
    String parm = "";
    if(ipString!=null&&ipString.trim().length()>0)
      parm +=ipString.trim();
    else {
      return null;
    }
    String lines =  ConnectInterfaceThird(ADD_URL,parm);
//处理业务
    List list = new ArrayList();
           
    if( lines.trim().length()>0)
    {
          if(lines.indexOf("client") == -1)
          {
            map.put("NOTFOUND","1");
            return map;
          }
//        String[] strings = lines.split("<h4>");
          JSONObject jsonObject = JSONObject.fromObject(lines);//String转换为JSON
          JSONArray jsonResultsArray = jsonObject.getJSONArray("results");
          String succ = jsonObject.getString("success");
          for (Object resultsObj : jsonResultsArray) 
          {
              JSONObject jsonResultsObj = (JSONObject) resultsObj;
              String dateString = jsonResultsObj.getString("date");
              SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss",Locale.US);//日期是Jul英文格式,parse需要加Locale.US
              SimpleDateFormat sdf_CN = new SimpleDateFormat("yyyy年MM月dd日     HH时mm分ss秒");
              Date date = null;
              try {
                date = sdf.parse(dateString);
              } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              String dateString_CN = sdf_CN.format(date);
              String client = jsonResultsObj.getString("client");
              Map resIPMap = queryipLib(client,0);
              if(resIPMap.get(EXCEPTION_MESSAGE)==null||resIPMap.get(EXCEPTION_MESSAGE).toString().trim().length()==0) 
              {
                Map tempMap = new HashMap();
                tempMap.put("ip", client);
                tempMap.put("resulttime", dateString_CN);
                tempMap.put("resultOwnLand", resIPMap.get("resOwnLand").toString());
               
                tempMap.put("resultIsp", resIPMap.get("resIsp").toString());
                tempMap.put("resultArea", resIPMap.get("resArea").toString());
                
                list.add(tempMap);
              }
          }
          
          
           map.put("res", list) ;
            
    }
    else {
            map.put(H***E_EXCEPTION,new Boolean(true));
    }
        return map;
       
}
</span>




                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: