0

我正在尝试使用Android JSON库,但是版本很旧,并且JSONObject中没有接受InputStream的构造函数,只有一个字符串。我无法将流的所有内容读入字符串,因为它比最大长度长。有没有办法在构造函数之后向 JSONObject 添加数据?如果没有,我该如何升级Android中的版本?

4

2 回答 2

1

为什么不使用 Gson Api,它是 Google 的第三方 API。检查以下链接:

http://code.google.com/p/google-gson/

https://sites.google.com/site/gson/gson-user-guide

于 2012-09-21T05:23:39.173 回答
0

尝试使用我的开源库:http ://code.google.com/p/android-json-rpc/ 没有输入流,但直接调用 JSON REST 服务。

您还可以覆盖 JSONObject 类,如下所示:

package com.m4bce.loisirs_ch;

import java.io.IOException;
import java.io.InputStream;

import org.json.JSONObject;

public class JSONObjectStream extends JSONObject {

    public JSONObjectStream(InputStream is) throws IOException {
        super();

        // your code here
    }

}

我希望这会有所帮助。

于 2012-09-21T12:59:01.677 回答