本文整理汇总了Java中net.sf.json.xml.XMLSerializer.read方法的典型用法代码示例。如果您正苦于以下问题:Java XMLSerializer.read方法的具体用法?Java XMLSerializer.read怎么用?Java XMLSerializer.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.json.xml.XMLSerializer
的用法示例。
在下文中一共展示了XMLSerializer.read方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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
}
}
示例7: 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;
}
示例8: 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};
}
示例9: 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);
}
示例10: xml2json
import net.sf.json.xml.XMLSerializer; //导入方法依赖的package包/类
/**
* 将xml字符串<STRONG>转换</STRONG>为JSON字符串
*
* @param xmlString
* xml字符串
* @return JSON<STRONG>对象</STRONG>
*/
public static String xml2json(String xmlString) {
XMLSerializer xmlSerializer = new XMLSerializer();
JSON json = xmlSerializer.read(xmlString);
return json.toString(1);
}