我能够以这种格式打印我的输出,System.out.println(map.get("email"));//this is printing fine
但在将其分配给字符串变量后我无法打印相同的值。我试过:String email=(String) map.get("email");
System.out.println("Email--"+email);//But this is not printing
如何将地图值转换为字符串?请帮我。
我的完整代码:
String url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token="
+ authResponse.accessToken;
final StringBuffer r = new StringBuffer();
final URL u = new URL(url);
final URLConnection uc = u.openConnection();
final int end = 1000;
InputStreamReader isr = null;
BufferedReader br = null;
isr = new InputStreamReader(uc.getInputStream());
br = new BufferedReader(isr);
final int chk = 0;
String pat = "\"(.*)\": \"(.*)\",";
Pattern pattern = Pattern.compile(pat);
Matcher matcher = null;
Map map = new HashMap();
while ((url = br.readLine()) != null)
{
if ((chk >= 0) && ((chk < end))) {
matcher = pattern.matcher(url);
if(matcher.find()) {
map.put(matcher.group(1), matcher.group(2));
}
//r.append(url).append('\n');
}
}
System.out.println(map.get("email"));
String email=(String) map.get("email");
System.out.println(email);