gpt4 book ai didi

android - android 中的 xml 到 json

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:52:00 26 4
gpt4 key购买 nike

我想做的是我正在制作一个应用程序引擎,我必须在其中解析类似于下面示例的 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 - android 中的 xml 到 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10908664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com