当前位置: 首页>>代码示例>>Java>>正文


Java XMLSerializer类代码示例

本文整理汇总了Java中net.sf.json.xml.XMLSerializer的典型用法代码示例。如果您正苦于以下问题:Java XMLSerializer类的具体用法?Java XMLSerializer怎么用?Java XMLSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XMLSerializer类属于net.sf.json.xml包,在下文中一共展示了XMLSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_xml

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
public void test_xml() throws Exception {
    XMLSerializer xmlSerializer = new XMLSerializer();
    
    JSONObject json = new JSONObject();
    json.put("id", 123);
    json.put("name", "jobs");
    json.put("flag", true);
    
    JSONArray items = new JSONArray();
    items.add("x");
    items.add(234);
    items.add(false);
    json.put("items", items);
    
    String text = xmlSerializer.write(json);
    System.out.println(text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:JSONLibXmlTest.java

示例2: doGet

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//    	response.setContentType("text/html;charset=UTF-8");
    	response.setCharacterEncoding("UTF-8");// 解决乱码问题
    	request.setCharacterEncoding("UTF-8");
    		PrintWriter out= response.getWriter();
        	String hphm  = new String(request.getParameter("carno").getBytes("ISO-8859-1"),"utf-8");//解决get连接中文乱码
        	String classno=request.getParameter("classno");
        	String engineno=request.getParameter("engineno");
        	String cityid=request.getParameter("cityid");
        	String cartype=request.getParameter("cartype");
        	String carInfo = "{hphm="+hphm+"&classno="+classno+"&engineno="+engineno+"&city_id="+cityid+"&car_type="+cartype+"}";
    		String sb =WeizhangTexst. getWeizhangInfoPost(carInfo);
        	JSONObject jsonObject = JSONObject.fromObject(sb);  
        	System.out.println(hphm);
            String xmlstr = new XMLSerializer().write(jsonObject); 
        	 out.print(xmlstr);
    }
 
开发者ID:jialiuyang,项目名称:appBack,代码行数:18,代码来源:queryCarXmlServlet.java

示例3: dealPsychicDefine

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
private void dealPsychicDefine(AGContext core, Map<String, ArbitraryGenProcessor> processors, JSONArray fileArray) {
    if (fileArray == null || fileArray.isEmpty()) {
        Log.i(TAG, "scan out psychic define file list is nil.");
        return;
    }
    ArbitraryGenProcessor psychicProcessor = processors.get("psychic-processor");
    for (int i = 0; i < fileArray.size(); i++) {
        String path = fileArray.optString(i);
        if (Util.isNullOrNil(path)) {
            Log.i(TAG, "file path is null or nil.");
            continue;
        }
        XMLSerializer ss = new XMLSerializer();
        ss.setTypeHintsEnabled(false);
        ss.setTypeHintsCompatibility(false);
        Log.i(TAG, "process src : %s", path);
        String rawContent = FileOperation.read(path);
        JSONObject json = (JSONObject) ss.read(RuntimeContextHelper.replace(rawContent));
        if (json == null) {
            Log.i(TAG, "read JSONObject from XML file(%s) failed.", path);
            continue;
        }
        json = JSONArgsUtils.validKey(json);
        psychicProcessor.exec(core, processors, json);
    }
}
 
开发者ID:AlbieLiang,项目名称:ArbitraryGen,代码行数:27,代码来源:PsychicAGEngine.java

示例4: xml2ArrayForObject

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
/**
 * 将xml中列表信息转化对象数组
 * 
 * @param xml
 * @param beanClass
 * @return
 */
public static Object[] xml2ArrayForObject(String xml, Class beanClass) {

	// 设置root为数组
	xml = setXmlRootAttrToArray(xml);
	XMLSerializer xmlSer = new XMLSerializer();
	JSON jsonArr = xmlSer.read(xml);
	Object[] objArr = new Object[jsonArr.size()];

	for (int i = 0; i < jsonArr.size(); i++) {
		objArr[i] = JSONObject.toBean(
				((JSONArray) jsonArr).getJSONObject(i), beanClass);
	}

	return objArr;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:23,代码来源:JSONXOperUtils.java

示例5: makeAPIRequest

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
public JSONObject makeAPIRequest(String apiFunction, @Nullable MultivaluedMap<String, String> params) {
    ClientResponse clientResponse = makeAPIResource(apiFunction, params).get(ClientResponse.class);

    log.info(clientResponse.getLocation());

    String response = clientResponse.getEntity(String.class);

    System.out.println(response);
    log.info("response: " + response);

    if (!method.equals("json/")) {
        XMLSerializer xmlSerializer = new XMLSerializer();
        JSON json = xmlSerializer.read(response);

        System.out.println(json);

        return JSONObject.fromObject(json);
    } else
        return JSONObject.fromObject(response);
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:21,代码来源:AbstractApiTest.java

示例6: weather

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
@JayMd(value = { "天气", "weather" })
@JayDoc("Query the weather in China mainland")
public static void weather(JayFunc func) throws UnsupportedEncodingException {
    JayArgs arg = func.getArgs();
    String city = arg.getArg(0, "上海");
    String day = arg.getArg(1, "0");
    if(arg.getArgAmount() >= 2 && DAYS.containsKey(day)) {
        day = DAYS.getString(day);
    }
    city = URLEncoder.encode(city,"gb2312");
    String url = SINA_WEATHER_URL.replace("${city}", city).replace("${day}", day);
    String xml = HttpUtils.getString(url);
    if(StringUtils.isEmpty(xml)) {
        func.setResult(JSONObject.parse("<msg>Not found!</msg>"));
        return;
    }
    String json = new XMLSerializer().read(xml).toString();
    Object result = JSONObject.parse(json);
    if(result instanceof JSONArray) {
        JSONArray arr = (JSONArray) result;
        if(arr.isEmpty()) {
            func.setResult(JSONObject.parse("<msg>Not found!</msg>"));
            return;
        }
        func.setResult(arr.get(0));
    } else {
        func.setResult(result);
    }
}
 
开发者ID:menyouping,项目名称:jay-lang,代码行数:30,代码来源:Weather.java

示例7: convertJsonToXml

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
public String convertJsonToXml(JSONArray jsonArray) {
    XMLSerializer serializer = new XMLSerializer();
    serializer.setTypeHintsEnabled(false);
    serializer.setForceTopLevelObject(true);
    serializer.setElementName("Schedule");
    serializer.setRootName("Schedules");
    return serializer.write(jsonArray);
}
 
开发者ID:helicalinsight,项目名称:helicalinsight,代码行数:9,代码来源:XmlOperation.java

示例8: convertXmlStringToJSon

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
public JSON convertXmlStringToJSon(String xmlData) {
    JSON json;
    XMLSerializer xmlSerializer = new XMLSerializer();
    xmlSerializer.setForceTopLevelObject(false);
    json = xmlSerializer.read(xmlData);
    return json;
}
 
开发者ID:helicalinsight,项目名称:helicalinsight,代码行数:8,代码来源:XmlOperation.java

示例9: exec

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
@Override
public JSONObject exec(AGContext context, Map<String, ArbitraryGenProcessor> processors, JSONObject args) {
    String name = args.optString("_name");
    if (Util.isNullOrNil(name)) {
        Log.i(TAG, "exec failed, name is null.");
        return null;
    }
    JSONObject result = context.execProcess(processors, "parse-rule", args);
    if (result == null) {
        Log.i(TAG, "parse rule result is null.");
        return null;
    }
    JSONArray fileArray = result.optJSONArray("fileArray");
    if (fileArray == null) {
        Log.i(TAG, "file array is null.");
        return null;
    }
    JSONArray jsonArray = new JSONArray();
    for (int i = 0; i < fileArray.size(); i++) {
        String path = fileArray.optString(i);
        XMLSerializer ss = new XMLSerializer();
        ss.setTypeHintsEnabled(false);
        ss.setTypeHintsCompatibility(false);
        Log.i(TAG, "process parse xml file : %s", path);
        JSONObject jsonObject = (JSONObject) ss.read(RuntimeContextHelper.replace(FileOperation.read(path)));
        if (jsonObject != null) {
            jsonObject = JSONArgsUtils.validKey(jsonObject);
            jsonArray.add(jsonObject);
        }
    }
    JSONObject r = new JSONObject();
    r.put(name, jsonArray);
    return r;
}
 
开发者ID:AlbieLiang,项目名称:ArbitraryGen,代码行数:35,代码来源:ParseXmlProcessor.java

示例10: process

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
@Override
public void process(String src, String destPath) {
	if (src == null || destPath == null) {
		throw new RuntimeException(String.format("src file(%s) or dest path(%s) is null.", src, destPath));
	}
	File file = new File(src);
	if (!file.exists() || !file.isFile()) {
		throw new RuntimeException(String.format("src file(%s) do not exist.", src));
	}

	XMLSerializer ss = new XMLSerializer();
	ss.setTypeHintsEnabled(false);
	ss.setTypeHintsCompatibility(false);
	Log.i(TAG, "process src : %s", src);
	JSONObject json = (JSONObject) ss.read(RuntimeContextHelper.replace(FileOperation.read(src)));
	
	TaskInfo info = new TaskInfo();
	info.script = mCoreScript;
	info.destPath = destPath;
	info.templateLibs = mTemplateCfg.getTemplateLibs();
	info.templateSuffix = Util.nullAsNil(Util.getSuffix(src));
	
	for (PsychicGenerator worker : mWorkers) {
		if (worker instanceof AGPsychicWorker) {
			if (info.templateSuffix.equalsIgnoreCase(((AGPsychicWorker) worker).getSupportSuffix())) {
				worker.genCode(mScriptEngine, json, info);
				continue;
			}
		}
		if (worker instanceof AGPyroWorker) {
			if (isSupportSuffix((AGPyroWorker) worker, info.templateSuffix)) {
				worker.genCode(mScriptEngine, json, info);
				continue;
			}
		}
		// Add more case here
	}
}
 
开发者ID:AlbieLiang,项目名称:ArbitraryGen,代码行数:39,代码来源:JsTemplateProcessor.java

示例11: xml2Map

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
/**
 * 将简单xml中信息转化Map<br>
 * 
 * @param xml
 * @return
 */
public static Map xml2Map(String xml) {
	//案例:
	//<object><id type="string">77777</id><userName type="string">chenyc</userName></object>
	XMLSerializer xmlSer = new XMLSerializer();
	JSON json = xmlSer.read(xml);
	
	return (JSONObject)json;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:15,代码来源:JSONXOperUtils.java

示例12: xml2ArrayForMap

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
/**
 * 将xml中列表信息转化对象数组
 * 
 * @param xml
 * @return
 */
public static Object[] xml2ArrayForMap(String xml) {

	// 设置root为数组
	xml = setXmlRootAttrToArray(xml);
	XMLSerializer xmlSer = new XMLSerializer();
	JSON json = xmlSer.read(xml);
	if(json.isArray()){
		return ((JSONArray) json).toArray();
	}
	return new Object[]{json};
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:18,代码来源:JSONXOperUtils.java

示例13: ConvertXMLtoJSON

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
public static String ConvertXMLtoJSON(String xml)  {  
	XMLSerializer xmlSerializer = new XMLSerializer();  
	JSON json =null;
	  
       json = xmlSerializer.read(xml);  
	return json.toString(1);  
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:8,代码来源:Feature.java

示例14: currentAlarmMessage

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
/**
* 解析告警信息
* @param str
* @return
*/
public String currentAlarmMessage(String str){
	String message = "";
	JSONObject object = JSONObject.fromObject(str);
	XMLSerializer xmlSerializer = new XMLSerializer();
	String xml = xmlSerializer.write(JSONSerializer.toJSON(object));
	String xml2 =xml.replace("<o>","").replace("</o>","").replace("<e class=\"object\">","").replace("</e>",""); 
	Alarm alarm = new Alarm(xml2);
	message = alarm.getOpsMessage3();
	return message;
}
 
开发者ID:HuaweiSNC,项目名称:OpsDev,代码行数:16,代码来源:SocketClient.java

示例15: exeExportCommand

import net.sf.json.xml.XMLSerializer; //导入依赖的package包/类
private JSON exeExportCommand(String command) throws Exception {
	try {
		// puting json in result.
		return new XMLSerializer().read(exeCommand(command).replaceAll(
				"NaN", "0"));
	} catch (Exception e) {
		logger.error("Could not run export command." + e.getMessage());
		throw new AnkushException("Coud not run export command.");
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:11,代码来源:Graph.java


注:本文中的net.sf.json.xml.XMLSerializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。