当前位置:编程学习 > JAVA >>

JSONObject in axis2?

我现在用eclipse开发一个Webservice,主要工作就是处理XML 和Json的互转

然后我下载Json-lib包

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;



                      ***************************
XMLSerializer xmlser=new XMLSerializer();
JSON route_json=xmlser.read(json_string);
JSONObject route_jsonobj=JSONObject.fromObject(route_json);

                       ***************************

 发布服务后
     会报两种错误
第一种:
      Exception in thread "main" org.apache.axis2.AxisFault: java.lang.ExceptionInInitializerError
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at client.UjServiceForAdjustServiceStub.getJson_XML(UjServiceForAdjustServiceStub.java:593)
at testpack.XmltoJson.main(XmltoJson.java:45)
第二种:
     Exception in thread "main" org.apache.axis2.AxisFault: Could not initialize class net.sf.json.xml.XMLSerializer
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at client.UjServiceForAdjustServiceStub.getJson_XML(UjServiceForAdjustServiceStub.java:593)
at testpack.XmltoJson.main(XmltoJson.java:45)


 望高手帮帮忙,一直纠结....

   万分感谢!.... --------------------编程问答-------------------- 解释一下:
XMLSerializer xmlser=new XMLSerializer();

JSON route_json=xmlser.read(json_string);
 //上面的json_string 具体的应该写成xml_string,是XML文件的内容字符串

JSONObject route_jsonobj=JSONObject.fromObject(route_json);
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,