In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to parse and read data in Android. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Data parsing and reading
The organization of data in network transmission: xml, json, http
(1) xml: extensible markup language
Features: save a small amount of data, cross-platform
Parsing methods: sax, dom, pull
A. sax parsing:
Features: high speed, less memory. Event-driven, not all content is loaded into memory at once.
StartElement: element node start
LocalName: tag name without prefix
QName: tag name with prefix
Attributes: attributes and values within a node
Xiao Ming
(2) dom resolution:
Features: load all content into memory at once
For server-side programming
(3) pull resolution:
Features: similar to sax, not automatically read
Suitable for mobile devices, taking up less memory
Json parsing
Features: more space-saving than xml
(1) json object: {"key1": "value1", "key2": "value2"}
a. Start and end with {}
B. Key must be a string, and value can be the underlying data type, String, json object, json array
c. Each piece of data is separated by a comma
Example:
{"name": "Xiaoming", "age": 25, "married": "true"}
(2) Analysis of json
/ / get an object of type JSONObject based on the string passed in
JSONObject jsonObject = new JSONObject (str)
/ / obtain the corresponding data according to key
String name = jsonObject.getString ("name")
Int age = jsonObject.getInt ("age")
Boolean b = jsonObject.getBoolean ("married")
/ / pass data into jsonOnject
JsonObject.put ("name", "Xiao Hong")
JsonObject.put ("age", 20)
JsonObject.put ("married", "false")
(3) JSONArray json array
a. Start and end with []
b. Each piece of data is a jsonObject
c. Each piece of data is separated by a comma
Example:
[{"name": "Xiao Ming", "age": 25, "sex": "male"}, {"name": "Xiao Hong", "age": 23, "sex": "female"}]
Parsing a piece of data in JSONArray format
/ / get an object of type JSONArray based on the passed string
JSONArray jsonArray = new JSONArray (str)
For (int item0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.