我在解析 json 时遇到这个错误。谁能帮我解决这个问题。
{
"website": [
"http://www.example.com",
"https://buy.example.com"
],
"number": [
"4546",
"54256456"
],
"email": [
"exam@gmail.com",
"example@gmail.com"
],
"address": [
"any adddress here",
"Address 2"
]
}
任何人都可以帮助我如何准确解析这个 json...
Json解析代码
String JSON_STRING = response.body().string();
Log.e("json_string", JSON_STRING.toString());
//Toast.makeText( getApplicationContext(), "Response : "+JSON_STRING, Toast.LENGTH_LONG ).show();
JSONObject object = new JSONObject( JSON_STRING );
JSONArray jsonArray = object.getJSONArray( "website" );
for (int i=0; i<jsonArray.length(); i++)
{
JSONObject website = jsonArray.getJSONObject( i );
Log.e("website", website.toString());
}
最佳答案
试试这段代码
try {
JSONObject jsonObject = new JSONObject(json);
JSONArray websites = jsonObject.getJSONArray("website");
for (int i = 0; i < websites.length(); i++) {
Log.d("TAG", websites.getString(i));
}
} catch (Exception e) {
e.printStackTrace();
}
关于java - 解析时报错org.json.JSONException : Value at 0 of type java. lang.String cannot be converted to JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55515797/