Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
blackberry中的json解析?_Json_Blackberry - Fatal编程技术网

blackberry中的json解析?

blackberry中的json解析?,json,blackberry,Json,Blackberry,我正在使用JSON开发一个web服务应用程序。 在执行任务时,我通过点击URL成功地直接获取JSOn响应 现在我有一个任务要请求,带有一个请求参数 enter code here private void callJSON_Webservice(String method,String paraLastModifiedDate) { HttpConnection c=null; InputStream is = null; String feedU

我正在使用JSON开发一个web服务应用程序。 在执行任务时,我通过点击URL成功地直接获取JSOn响应

现在我有一个任务要请求,带有一个请求参数

enter code here
private void callJSON_Webservice(String method,String paraLastModifiedDate) {
        HttpConnection c=null;
        InputStream is = null;
        String feedURL = Constants.feedURL;
        int rc;

        try{
            JSONObject postObject = new JSONObject();
            postObject.put("CheckLatestDataDate",method);
            postObject.put("LastModifiedDate", paraLastModifiedDate);
            //c = new HttpConnectionFactory().getHttpConnection(feedURL);
            c = (HttpConnection)Connector.open(feedURL + ConnectionManager.getConnectionString());

            // Set the request method and headers
            c.setRequestMethod(HttpConnection.GET);
            c.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
            c.setRequestProperty("Content-Length", "" + (postObject.toString().length() - 2));
            //c.setRequestProperty("method", HttpConnection.GET);

            // Getting the response code will open the connection,
            // send the request, and read the HTTP response headers.
            // The headers are stored until requested.
            rc = c.getResponseCode();

            if (rc != HttpConnection.HTTP_OK){
                throw new IOException("HTTP response code: " + rc);
            }

            is = c.openInputStream();

            String json = StringUtils.convertStreamToString(is);
            object = new JSONObject(json);


        }catch (Exception e) {
            System.out.println(e+"call webservice exception");
        }

    }
有了这段代码,我得到了EOF异常。我需要尽快完成这项小任务。请帮帮我。。。! 提前更换Thanx

尝试更换

is=c.openInputStream();
String json=StringUtils.convertStreamToString(is);
包括:

is=c.openInputStream();
StringBuffer=新的StringBuffer();
int ch=0;
while(ch!=-1){
ch=is.read();
append((char)ch);
}
字符串json=buffer.toString();


参考资料:

Rupak,我对用JSON和XML发送请求参数感到非常困惑,我已经通过发布请求参数执行了XML解析,但无法用JSON完成。请提供一些示例代码或代码片段来指导我,从核心开始。检查这些链接,,thanz alot Rupak,这真的是一个很大的帮助。。。!我已经完成了这项任务。并得到了我的数据。向服务器发送请求的步骤与xml解析的步骤类似,只是我们需要处理以JSON形式得到的响应。我一辈子都在想。Thanx对社区非常重要。