1.需解析JSON数据:
json
2.需求:取出gender_type值;
3.
import org.json.JSONObject;
public void dealJson(String text){
JSONObject jsonObject = new org.json.JSONObject(text); //将String类型的数据转换为JSONObject对象
JSONObject dataJson = jsonObject.getJSONObject("data"); //使用getJSONObject方法取出data的JSONObject对象
JSONObject resultJson = dataJson.getJSONObject("result");
JSONObject genderJson = resultJson.getJSONObject("gender");
System.out.println("genderJson==>"genderJson);
String gender = genderJson.getString("gender_type"); //取出gender_type的值
System.out.println("gender==>"+gender);
}
//方法不少,这里仅提供其中一种学习
更多Java学习资料可关注:gzitcastspa