You can try this way as well. I have tried and tested it myself.

Step 1 : Please Download thejava-json.jar

Step 2: Add this to/libsfolder of your project then add to build path.

Step 3: Then use it as follows

  • Imports to look for

    import org.json.JSONException; import org.json.JSONObject; import org.json.XML;
  • Sample string

    String sampleXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<mobilegate>" +"<timestamp>232423423423</timestamp>" + "<txn>" + "Transaction" + "</txn>" + "<amt>" + 0 + "</amt>" + "</mobilegate>"; 
  • Json String

    JSONObject jsonObj = null; try { jsonObj = XML.toJSONObject(sampleXml); } catch (JSONException e) { Log.e("JSON exception", e.getMessage()); e.printStackTrace(); } Log.d("XML", sampleXml); Log.d("JSON", jsonObj.toString());

Output:

XML:

<?xml version="1.0" encoding="utf-8"?><mobilegate><timestamp>232423423423</timestamp><txn>Transaction</txn><amt>0</amt></mobilegate>

JSON :

{"mobilegate":{"timestamp":232423423423,"amt":0,"txn":"Transaction"}}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android启动过程
  2. 3.Spinner
  3. Android(安卓)RecyclerView 设置显示滚动
  4. 【Android】HTTP协议的经典讲解
  5. 关于android的广播机制里面的网络状态监
  6. Android重要控件概览(中)
  7. Android进程间通信--消息机制及IPC机制实
  8. 转:android在文本TextView中添加超链接
  9. android 横竖屏判断
  10. android 控件学习笔记 --------ViewPager