-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonobject.java
More file actions
32 lines (24 loc) · 897 Bytes
/
Jsonobject.java
File metadata and controls
32 lines (24 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import org.json.JSONObject;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Scanner;
public class Jsonobject {
public static void geocoding(String username) throws Exception {
String s = "https://api.github.com/users/";
s += URLEncoder.encode(username, "UTF-8");
URL url = new URL(s);
// read from the URL
Scanner scan = new Scanner(url.openStream());
String str = new String();
while (scan.hasNext())
str += scan.nextLine();
scan.close();
// build a JSON object
JSONObject obj = new JSONObject(str);
// get the result
System.out.println("JSONObject:");
System.out.println("Name: "+obj.getString("name"));
System.out.println("followers:"+obj.getInt("followers"));
System.out.println("public_repos:"+obj.getInt("public_repos"));
}
}