解析Android中简单的字符串JSON [英] Parse simple string JSon in Android

查看:130
本文介绍了解析Android中简单的字符串JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

String response = webService.webGet("");  the response of the web service

String LargeImage = new Gson().fromJson(response,String.class);

byte[] imageByteArray = Base64.decode(LargeImage);

回应是这样的:iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCA ​​...周围有400.000字符一个Base64连接codeD映像

response is like: "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCA... " a Base64 encoded image having around 400.000 characters.

响应来自web服务非常快。当它尝试了一段时间后GSON解析它(如20-30秒)我得到一个错误与内存不足。我怎么能不解析此GSON简单的字符串,它应该是相当简单的,但我不知道该怎么做。
请建议我。谢谢你的时间

The response comes very quick from the web service. When it tries to parse it with Gson after a while (like 20-30 seconds) I get an error with out of memory. How can I parse this simple string without Gson, it should be fairly simple but I don't know how to do it. Please advise me. Thank you for your time

推荐答案

更改您的Base64图像编码成一个URL,你可以直接下载图像。

Change your Base64 image encoding into a URL where you can download the image directly.

然后去获得flexjson 2.1,您可以在几行字在Android解析JSON变得非常容易。它也比GSON快。

Then go get flexjson 2.1 and you can parse JSON on Android very easily in a few lines. It's also faster than GSON.

http://flexjson.sourceforge.net

但是,从您的文章,它看起来像你刚刚超过JSON发送Base64编码的图像作为一个字符串。没有必要在这种情况下使用JSON。除非你打算缠绕它的一些元数据在未来。

But from your post it looks like you're just sending the Base64 image over JSON as a single string. No need to use JSON in that case. Unless you plan on wrapping some metadata around it in the future.

另外跳过存储在所述DB中的图像。只是把它写到文件系统,并把链接到你的对象在数据库中的文件路径。很多调试时,你不知道你下载什么形象等更容易。

Also skip storing the image in the DB. Just write it to the filesystem, and put the file path in the DB linked to your object. Much easier to debug when you wonder what image you downloaded, etc.

这篇关于解析Android中简单的字符串JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆