json之jackson 在java中的应用

 
	for(var i=1; i<data.length-1; i++){
    			alert(data);
    			alert(data[i].id+"="+data[i].name);
    		}




 
	@RequestMapping(value="/carmaker", method = RequestMethod.GET)
  	public @ResponseBody List<Object> getCarMaker(){
		  String json = "[{\"id\": \"address2\",\"name\":\"haha2\"}]";//模板JSON
		  ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
		 
			try {
				List<Object> userData = mapper.readValue(json, List.class);
				  List<CarMake> list =CarMake.findAllCarMakes();
				  for (CarMake vo : list) {
					  Map<String,String> nameStruct = new HashMap<String,String>();
					  nameStruct.put("id", vo.getId()+"");
					  nameStruct.put("name", vo.getName());
					 userData.add(nameStruct);
				  }
				  return userData;
			} catch (JsonParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JsonMappingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 
		return null;
  	}                                                                                            

你可能感兴趣的:(json之jackson 在java中的应用)