android中的xml到json

我想做的是,我正在制作一个应用引擎,我必须解析xml,类似于下面的例子和其他类似的xml.我想把它转换成json ….有没有办法这样做?

 - <application>
    - <!--  [Start] Application Section 
      --> `enter code here`
      <app_type>app_business</app_type> 
    - <app_info>
      <app_name>App test for test user</app_name> 
      <app_description>app description</app_description> 
      <app_keywords>4464</app_keywords> 
      <app_website>www.google.co.in</app_website> 
      <app_logo>1335504801.jpg</app_logo> 
      <splash_screen_logo>Splash.jpg</splash_screen_logo> 
      <mobile_platform>0</mobile_platform> 
      <header_bg /> 
      <bg_image /> 
      <bg_color /> 
      <usr_name>Test Singh</usr_name> 
      <usr_username>test</usr_username> 
      <usr_email>test@gmail.com</usr_email> 
      <usr_registerDate>2012-04-26 10:21:00</usr_registerDate> 
      <usr_plan_id>1</usr_plan_id> 
      <usr_lastvisitDate>2012-04-30 04:24:34</usr_lastvisitDate> 
      <usr_plan_id>1</usr_plan_id> 
      <usr_gender>Male</usr_gender> 
      <usr_contactno>12321432</usr_contactno> 
      <usr_address>Jaipur</usr_address> 
      <usr_profile_picture>1234514Sunset.jpg</usr_profile_picture> 
      <usr_dob>2012-04-09</usr_dob> 
      </app_info>
    - <app_home>
    - <!--  [Start]Home Section 
      --> 
    - <!--  Home properties 
      --> 
    - <home_properties>
      <tab_icon>home.png</tab_icon> 
      <tab_title>Home</tab_title> 
      <banner_text>Home Banner Text here.</banner_text> 
      <bg_image>business_logo1.png</bg_image> 
      </home_properties>
    - <!--  Home Buttons 
      --> 
    - <home_buttons>
    - <button>
      <button_type>app_portfolio</button_type> 
      <button_text>Portfolio</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
    - <button>
      <button_type>app_websiteUrl</button_type> 
      <button_text>Web Url</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
    - <button>
      <button_type>app_contact</button_type> 
      <button_text>Contact</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
      </home_buttons>
      </app_home>
    - <!--  [End]Home Section 
      --> 
    - <app_aboutus>
    - <!--  [Start]About Us Section 
      --> 
    - <!--  [Start]Home properties 
      --> 
    - <aboutus_properties>
      <tab_icon>aboutus.png</tab_icon> 
      <tab_title>About Us Tab</tab_title> 
      <banner_text>About Us Banner Text</banner_text> 
      <bg_image>bg-image.jpg</bg_image> 
      <image>about-img.jpg</image> 
      <description>About us description</description> 
      </aboutus_properties>
    - <!--  [End]Home properties 
      --> 
      </app_aboutus>
    - <!--  [End]About Us Section 
      --> 
    - <app_services>
    - <!--  [Start]Services Section 
      --> 
    - <!-- [Start] Services properties 
      --> 
    - <services_properties>
      <tab_icon>2.png</tab_icon> 
      <tab_title>Services Tab Title</tab_title> 
      <banner_text>Services Banner Text</banner_text> 
      <bg_image>bg-image.jpg</bg_image> 
      <image>services.jpg</image> 
      <description>Services Description</description> 
      </services_properties>
    - <!--  [End]Services properties 
      --> 
      </app_services>
    - <!--  [End]Services Section 
      --> 
    - <app_more>
    - <!--  [Start]More Section 
      --> 
    - <!--  More properties 
      --> 
    - <more_properties>
      <tab_icon>more.png</tab_icon> 
      <tab_title>More</tab_title> 
      <banner_text>More Banner text</banner_text> 
      <bg_image>bg-image.jpg</bg_image> 
      </more_properties>
    - <!--  More Buttons 
      --> 
    - <more_buttons>
    - <button>
      <button_type>member profile</button_type> 
      <button_text>Member Profile</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
    - <button>
      <button_type>map</button_type> 
      <button_text>More Button map</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
    - <button>
      <button_type>audiovideo</button_type> 
      <button_text>Audio Video Streaming</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
    - <button>
      <button_type>news</button_type> 
      <button_text>News</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
    - <button>
      <button_type>services</button_type> 
      <button_text>Services</button_text> 
      <button_image>button.jpg</button_image> 
      </button>
      </more_buttons>
      </app_more>
    - <!--  [End]More Section 
      --> 
    - <app_news>
    - <!--  [Start]News Section 
      --> 
    - <!--  News properties 
      --> 
    - <news_properties>
      <tab_icon>2.png</tab_icon> 
      <tab_title>News Tab Title</tab_title> 
      <banner_text>News Banner Text</banner_text> 
      <bg_image>bg-image.jpg</bg_image> 
      <rss_url>http://newsrss.bbc.co.uk/rss/sportonline_world_edition/front_page/rss.xml</rss_url> 
      </news_properties>
      </app_news>
    </application>
最佳答案
通过使用this lib,您可以执行XML到JSON转换.

String xmlString = "<Root><FName>Hello</FName><LName>World</LName></Root>";
XMLSerializer serializer = new XMLSerializer();  
JSON json = serializer.read( xmlString );

查看this链接以供参考.

转载注明原文:android中的xml到json - 代码日志