【问题标题】:handling .JSON file in Android在 Android 中处理 .JSON 文件
【发布时间】:2011-12-10 09:23:31
【问题描述】:

如果从 Web 浏览器触发 URL 并下载 >JSON 文件,当 Web 服务直接返回我的 .JSON 文件时,我如何处理 JSON 响应?

【问题讨论】:

  • 我不明白。您的问题是读取 JSON 文件还是从特定 URL 下载它?
  • 在阅读中,我正在使用 BufferedReader readline() 将 InputStream 转换为 String,我正在做 while((line=br.readLine())1=null),我得到 NullPointerException。
  • 我猜文件没有被下载所以它给出了这个错误。
  • 使用浏览器访问网络服务时检查是否能够下载 JSON 字符串
  • 使用 webbrowser 我可以下载 .JSON 文件,但无法在 webbrowser 上查看

标签: android json file


【解决方案1】:

//这是什么while((line=br.readLine())1=null)

 if(response!=null){  
            sb = new StringBuilder();
            byte[] buffer = new byte[512];
            int bytes_read = 0;

            while((bytes_read = is.read(buffer, 0, buffer.length)) > 0)
            {
                sb.append( new String(buffer,0,bytes_read));
            } 
            System.out.println("Preview image Result=="+sb.toString());
        }

【讨论】:

  • while((line=br.readLine())1=null) 是 while((line=br.readLine())!=null)
  • 它也会给出 NullPointerException
猜你喜欢
  • 1970-01-01
  • 2017-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-02
  • 1970-01-01
相关资源
最近更新 更多