平常可能做得比较多是的解析json传参,如下
public static JSONObject parseRequestToJson(HttpServletRequest request, String charset) throws Exception {
return new JSONObject(getPostString(request, charset));
}
public static String getPostString(HttpServletRequest req, String charset) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
try {
br = new BufferedReader(new InputStreamReader((), charset));
String temp = "";
while ((temp = ()) != null) {
(temp);
(());
}
} catch (Exception e) {
();
} finally {
try {
if (br != null) {
();
}
} catch (Exception e1) {
();
}
}
return ();
}
main{
//得到json对象
JSONObject jo = parseRequestToJson(request,"utf-8");
//或则使用fastjson
Map<String,String[]> jsonFromSdkServer = ();
String response_key = ().iterator().next()[0];
JSONObject jsonParams = (response_key);
}
现在主要说说xml格式的怎么获取:
//其实也就4行代码
//得到post传递过来的xml的string
String xml = ("xml");
//DOM解析器工厂
dbf = ();
//DOM解析器对象
db = ();
//把得到的执行解析
org. parse = (new ByteArrayInputStream(()));
//得到xml中例如<name>haha</name>
String name = ("name").item(0).getFirstChild().getNodeValue();
//输出haha
(name);