java中使用JSONObject

下载https://download.csdn.net/download/ahaitongxue/10442655

测试

java文件

import org.json.JSONObject;
public class HelloWorld
{
public static void main(String[] args)
{
String data = "{\"data\":{\"expires_in\": \"36000\",\"scope\": \"\",\"refresh_token\": \"\",\"access_token\": \"6461171100c3bfa3cba24cc332d7d78b311d2bf590f4877c9\"},\"errno\": 0}";
try{
JSONObject joData = new JSONObject(data);
JSONObject jChild = joData.getJSONObject("data");
String token = jChild.getString("access_token");
System.out.println("HelloWorld:" + token);
}catch(Exception e){}
}

}

注意必须用try-catch包围

javac -cp json.jar HelloWorld.java

java -cp .:json.jar HelloWorld 


你可能感兴趣的:(android)