首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回StringBuffer阵列

返回StringBuffer阵列
EN

Stack Overflow用户
提问于 2012-01-19 09:51:57
回答 1查看 1K关注 0票数 1

我使用StringBuffer从web服务发送和接收变量。

我的代码是:

// connection = new (urlSCS+ "/login");connection = (HttpURLConnection) url.openConnection();connection.setRequestMethod("POST");

代码语言:javascript
复制
            connection.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded");

            connection.setRequestProperty("Content-Length",
                    "" + Integer.toString(urlParameters.getBytes().length));
            connection.setRequestProperty("Content-Language", "pl-PL");

            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);

            // Send request
            DataOutputStream wr = new DataOutputStream(
                    connection.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();

            // Get Response
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
            rd.close();

如何将此代码更改为能够接收数组而不是字符串?

我从web服务获得的请求如下:{"var", "var"}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-19 10:33:16

这可能对http://www.coderanch.com/t/393008/java/java/explode-Java有帮助

记住使用response.substring()从{}中删除响应!

看:

代码语言:javascript
复制
    String partsColl = "A,B,C";  
    String[] partsCollArr;  
    String delimiter = ",";  
    partsCollArr = partsColl.split(delimiter);

您将有您的响应在“所以子字符串他们”。祝好运!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8923973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档