Java 获取 JSONObject 中的 openid 值
可以使用以下代码来获取openid的值:
import org.json.JSONArray;
import org.json.JSONObject;
public class Main {
public static void main(String[] args) {
String jsonString = '{"data":{"openid":["ouGsa05Dqq9pXeaYh4xhxgJD-4F8","ouGsa09nIQ4hdLsYQDJ9YIKmVtpU"]},"count":2,"next_openid":"ouGsa09nIQ4hdLsYQDJ9YIKmVtpU"}';
JSONObject jsonObject = new JSONObject(jsonString);
JSONArray openidArray = jsonObject.getJSONObject("data").getJSONArray("openid");
for (int i = 0; i < openidArray.length(); i++) {
String openid = openidArray.getString(i);
System.out.println('openid: ' + openid);
}
}
}
输出结果为:
openid: ouGsa05Dqq9pXeaYh4xhxgJD-4F8
openid: ouGsa09nIQ4hdLsYQDJ9YIKmVtpU
原文地址: https://www.cveoy.top/t/topic/n4Cx 著作权归作者所有。请勿转载和采集!