简体   繁体   中英

How to send JSON data

I have quite much data to send to a server. The format is JSON and my platform is Android. I was wondering would it be wise to somehow divide the data in smaller packets, or send all the data at once? Also would it be good idea to run the sending code in a different thread? I use HTTPPost to send the data with Android

Creating smaller packets will cause a lot more overhead, thus a lot more data to send. Also, all networking should be executed on a separate thread (not UI thread).

Whether to use "many" HTTP requests or just one depends on your program flow. On one hand, you don't want to send data over the network that you are not sure you will need, so one catch-EVERYTHING post may be a bad idea. On the other, reducing the number of requests is going to reduce the overhead associated with each one, and thus result in less total time spent sending.

And yes, always perform network operations outside the UI thread. As far as the rest of the system is concerned, these are intolerably slow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM