Java – JSON vs simple string operation for parsing httprequest in Android
I am faced with the common situation that I have to extract some information from the remote server through httppost request. Imagine that we are retrieving some weather information in the weather application
The server sends a long input stream. We are interested in extracting some information from this stream. Remember, we are in a memory CPU binding environment
We have two options:
1) We use JSON or XML parsers to extract information
This is the recommended method, but it has some disadvantages:
>Painful wordiness, especially if we want to get little information from large traffic. > it should be faster and easier to collect garbage, but I'm not sure whether this is the case (small information from large traffic)
2) We use simple string manipulation (SSM):
We reduce the dimension of the input stream by pruning a lot of useless information, and then we extract information from compact strings. For this purpose, we can use static methods to build filters to reduce the work of the garbage collector
This method also has some disadvantages:
>I think it is strongly recommended not to use this method > the more information we extract, the slower this method will be. I think there is a key point in the slow performance curve of SSM. > it may not be as flexible as JSON or other stock parsers
But there are also some important advantages:
>Concise, user-friendly code. > modifying existing filters may be difficult, but creating new filters is much easier
In conclusion, the problem is:
1) Is simple string manipulation a big taboo method, or is it reasonable to consider using it? 2) If your answer to the previous question is yes (taboo), can you explain why?
Cheers:)
resolvent:
I will request information in JSON format (not more concise and less advantageous XML) and use an event based parser to locate the required data because it is read from the server
This is very easy in memory and does not need to change the content provided by the server. It also has higher reliability and resistance to change than any locally produced slicing solution you may put together
I have a free light weight pull parser for JSON on my website. Other products are from http://www.json.org Start supply