0

我是 android 世界的新手,我遇到了一些问题。我正在android下开发一个项目,它需要一个json解析器。我从 Zend 框架下开发的 Web 服务获取我的 json 文件,该 Web 服务的链接:“manganew:8080/wsmanganew/manga/manga/idmanga/1”,json 文件的内容是

{
"manga": [
            {
                "idmanga":"1",
                "titre":"naruto",
                "episode":"145",
                "url":"http:\/\/naruto.com\/",
                "image":null,
                "description":"Naruto Shippuuden .",
                "tv":"TV Tokyo",
                "dtdebut":"2013-05-23 12:30:00",
                "iduser":"1"
            }
        ]}

我正在关注本教程“ http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ ”。

我不知道如何索引 android 中的 Web 服务链接,任何帮助都会很有用。

谢谢你

4

2 回答 2

0

尝试这个

BufferedReader reader = new BufferedReader(new FileReader("C:\\file.json"));
String line, results = "";
while( (line = reader.readLine()) != null)
    results += line;

reader.close();

JSONObject obj = new JSONObject(results);

替换为您的本地机器下载字段路径C:\\file.json

于 2013-05-12T11:59:42.847 回答
0

那么,你需要做什么?将 json 对象从该 url 下载到您的应用程序中?该代码在其类中有方法 getJSONFromUrl,但您应该使用它,根据评论它有缺陷。

从文件中读取字符串使用此代码

BufferedReader reader = new BufferedReader(new FileReader("/mnt/sdcard/docs/file.json"));
String line, results = "";
while( (line = reader.readLine()) != null)
    results += line;

reader.close();

JSONObject obj = new JSONObject(results);

用文件路径替换路径

于 2013-05-12T00:41:45.873 回答