出力をこの形式で出力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);