package test;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
public class Test {
public static String signData = "<?xml version="1.0" encoding="utf-8"?><BodSignData version="1.0"><Field><Name>orderId</Name><DispName></DispName><Value>5001</Value></Field><Field><Name>payAccountNo</Name><DispName>kevin</DispName><Value>4775</Value></Field><Field><Name>amount</Name><DispName>undefined</DispName><Value>520</Value></Field><Field><Name>masterName</Name><DispName>undefined</DispName><Value>sn</Value></Field><Field><Name>payDate</Name><DispName>undefined</DispName><Value></Value></Field></BodSignData>";
public static void main(String[] args) {
/*JSONObject jsonObj = null;
try {
jsonObj = XML.toJSONObject(signData);
JSONObject jsonBodSignData = jsonObj.getJSONObject("BodSignData");
System.err.println(jsonBodSignData.toString());
JSONArray jsonField=jsonBodSignData.getJSONArray("Field");
System.err.println(jsonField);
for (int i = 0; i < jsonField.length(); i++) {
System.err.println(jsonField.get(i));
}
} catch (JSONException e) {
e.printStackTrace();
}
Log.e("XML", signData);
Log.e("JSON", jsonObj.toString());
//System.err.println(signData);
//System.err.println(jsonObj.toString());
*/
String resp="<?xml version="1.0" encoding="utf-8"?><request><filelist><treenode><!--code 0表示成功--><code>0</code></treenode></filelist></request>";
try {
JSONObject jsonObj = XML.toJSONObject(resp);
JSONObject jsonRequest = jsonObj.getJSONObject("request");
JSONObject jsonfilelist=jsonRequest.getJSONObject("filelist");
JSONObject jsontreenode=jsonfilelist.getJSONObject("treenode");
int jsoncode=jsontreenode.getInt("code");
System.err.println(jsoncode);
} catch (JSONException e) {
e.printStackTrace();
}
}
今天的文章 map转换为json字符串(map转换为jsonobject)分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/45284.html