类似这样的字符串,如何在android上用json解析???实际这是javascript对象

2025-04-15 19:31:39
推荐回答(1个)
回答1:

提供解析json的参考代码:
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-----------------
read1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View source) {
InputStream is = ReadJsonData.this.getResources()
.openRawResource(R.raw.test1);
String x;
try {
byte[] buffer = new byte[is.available()];
is.read(buffer);
String json = new String(buffer, "utf-8");
JSONObject act= new JSONObject(json);
x = act.getString("name");
Log.e("----name----", x);
x = act.getString("start");
Log.e("----age----", x);

} catch (Exception e) {

e.printStackTrace();
}
}
});