【问题标题】:conversion of xml data into string将xml数据转换为字符串
【发布时间】:2014-11-29 11:35:50
【问题描述】:

我得到的是 xml 格式的输出

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
<first-name>xxxxxxxxx</first-name>
<last-name>xxxxxxxx</last-name>
<email-address>xxxxxxxxxxxxxxxx</email-address>
</person>

我想以字符串形式读取值以进一步使用它。我的代码如下:

     String accesstok=AccessToken.toString();
     OAuthRequest request2 = new OAuthRequest(Verb.GET,"https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address)?oauth2_access_token="+accesstok);
     Response response2 = request2.send();

【问题讨论】:

标签: java xml json jsp servlets


【解决方案1】:

这似乎与how to manipulate HTTP json response data in Java 非常相似,也许那里的一些答案可以帮助你?我建议,就像我在那里所做的那样,查看 Scanner 分隔符、Scanner.findInLine 或 Scanner.findWithinHorizo​​n。

例如:

s.findWithinHorizon("<first-name>(\\w+)</first-name>");
MatchResult firstNameResult = s.match();
s.findWithinHorizon("<last-name>(\\w+)</last-name>");
MatchResult lastNameResult = s.match();
s.findWithinHorizon("<email-address>(\\w+)</email-address>");
MatchResult emailResult = s.match();

【讨论】:

    猜你喜欢
    • 2015-11-21
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 2012-10-26
    • 2023-03-07
    • 2012-10-10
    相关资源
    最近更新 更多