android - Volley 错误:org.json.JSONException:在字符 0 处输入结束,代码:null
问题描述
这是我对 JSON DATA 的回应:
{
"markers": [
{
"error": false,
"title": "name",
"lat": "17.415751",
"lng": "78.443277",
"video": "vlc-record-2020-02-14-16h29m53s-GlintandGlowJewellerypresentation.mp4",
"image": "51457.jpg",
"address": "Hyderabad,
"phone": "4023384555",
"name": "name"
}
]
}
这是我第一次制作解析 JSON 数据的安卓应用程序。但是,我遇到了关于 JSON 解析的错误。我试过用谷歌搜索这个问题,但大多数解决方案都对我不起作用。
我的请求看起来像这样:
RequestQueue req = Volley.newRequestQueue(getApplicationContext());
JSONObject jsonObject = null;
JsonObjectRequest strReq = new JsonObjectRequest(Request.Method.GET,
url,null, new Response.Listener<JSONObject>() {
//http://justasec.in/JustASec/jas.php
@Override
public void onResponse(JSONObject response) {
Log.e(TAG, "response: " + response);
try {
JSONObject obj = new JSONObject(response.toString());
JSONArray commentsObj = obj.getJSONArray("markers");
for (int i = 0; i < commentsObj.length(); i++) {
JSONObject commentObj = (JSONObject) commentsObj.get(i);
String title = commentObj.getString("title");
String address = commentObj.getString("address");
String phone = commentObj.getString("phone");
// String contact_person = commentObj.getString("contact_person");
lat = commentObj.getString("lat");
lng = commentObj.getString("lng");
/*Image = "http://amazearapp.com/jvdweb/images/medium/"+ commentObj.getString("images");
VIDEO_SAMPLE ="http://amazearapp.com/jvdweb/videos/" + commentObj.getString("video");
initializePlayer();
*/ mapView.getMapAsync(DataActivity.this);
Title.setText(title);
//Address.setText(address);
/* if (contact_person != null && !contact_person.isEmpty()) {
ContactPerson.setText(contact_person);
} else {
ContactPerson.setText("NA");
ContactPerson.setVisibility(View.GONE);
}*/
if (phone != null && !phone.isEmpty()) {
Number = phone;
} else {
Number = "NA";
call.setVisibility(View.GONE);
}
sliderImg = new ArrayList<>();
DiscountModel model = new DiscountModel();
model.setName("Image");
model.setImage(commentObj.getString("image"));
sliderImg.add(model);
if (commentObj.getString("video") != null) {
DiscountModel model1 = new DiscountModel();
model1.setName("Video");
model1.setImage(commentObj.getString("video"));
sliderImg.add(model1);
}
Log.v("size", sliderImg.size() + " ");
viewPagerAdapter = new ViewPagerAdapter(sliderImg,DataActivity.this);
viewPager.setAdapter(viewPagerAdapter);
}
} catch (JSONException e) {
Log.e(TAG, "json parsing error: " + e.getMessage());
// Toast.makeText(getApplicationContext(), "json parse error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse networkResponse = error.networkResponse;
Log.e(TAG, "Volley error: " + error.getMessage() + ", code: " + networkResponse);
// Toast.makeText(getApplicationContext(), "Server down", Toast.LENGTH_SHORT).show();
}
}){
解决方案
推荐阅读
- javascript - 为什么延迟修改 DOM?
- java - Javafx gif 内存泄漏
- php - 在 Woocommerce 购物车小部件中显示购物车项目数
- xcode - xCode:目前无法安装此应用程序。仅在添加 watchOS 扩展后出现此错误
- php - 在 Codeigniter 中进行插入时出现内部服务器错误
- layout - Flutter 如何在 ListTile 中使用文本字段?
- graphql-js - graphql-compose-mongoose 生成错误:预期 [object Object] 是 GraphQL 模式
- python-3.x - 如何使用 python3 从文本中拆分复合名词,例如物联网?
- c - 创建更通用的 makefile
- python-3.x - 为什么掷骰子模拟器需要两个功能?