用jquery,返回的data.weatherinfo.city

解决方案 »

  1.   

    可以先创建个jsonobjct jsonob=new jsonobject(json)  然后hashmap map=(hashmap)jsonob.get(“weatherinfo”)试试 看看能不能弄到hashmap里面 
      

  2.   

     public JSONObject getJSONObject(String key) 或者用这个方法也可以试试
      

  3.   

    用jackson-mapper-lgpl-1.9.2.jar 里面有各种解析
      

  4.   

    JSONObject jsonObj = (JSONObject)jParser.parse("楼主的字符串");
    Object obj = jsonObj .get ("weatherinfo");
    JSONObject subObj = (JSONObject)obj ;
    String city= (String)subObj .get("city");
      

  5.   

    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject; public void getJSONObject(){
            JSONObject node = JSONObject.fromObject("{'weatherinfo':{'city':'北京','cityid':'101010100','temp1':'-8℃','temp2':'4℃','weather':'晴','img1':'n0'}}");
            List<Object>  nodes = new ArrayList<Object>();
       
            JSONArray jsons = JSONArray.fromObject(node.get("weatherinfo"));
            
            for (Object o : jsons)
            {
                JSONObject jsonNode = JSONObject.fromObject(o);
                List<Object> treeNodes = new ArrayList<Object>();
                treeNodes.add(jsonNode.getString("city"));
                treeNodes.add(jsonNode.getString("cityid"));
                treeNodes.add(jsonNode.getString("temp1"));
                treeNodes.add(jsonNode.getString("temp2"));
                //...
                nodes.add(treeNodes);
            }
        
        System.out.println(nodes);
        }
      

  6.   

    如果你想要得到里面的信息的话 可以先在前台用json解析把它封装到Weatherinfo这个对象里面 再把Weatherinfo传到后台不就得了嘛 干嘛非要用java解析json呢 
      

  7.   

    也可以使用json-simple的各种解析
    示例和jar下载地址如下:
    http://code.google.com/p/json-simple/downloads/list
      

  8.   

    http://json-lib.sourceforge.net/
    我用的json-lib-jdk1.5
      

  9.   

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 是怎么回事呢