Java 如何在API上发布?
我是Android的初学者,我有麻烦了。如何使用API解析和发布任何东西 我有两个API: 第二个API工作正常并给出响应,但当我使用第一个API时,它不会生成响应,但在Postman上这两个API是相同的。我不知道我的代码出了什么问题 我想用第一个API替换第二个API 这是我的密码:Java 如何在API上发布?,java,php,android,api,Java,Php,Android,Api,我是Android的初学者,我有麻烦了。如何使用API解析和发布任何东西 我有两个API: 第二个API工作正常并给出响应,但当我使用第一个API时,它不会生成响应,但在Postman上这两个API是相同的。我不知道我的代码出了什么问题 我想用第一个API替换第二个API 这是我的密码: private void getEventTypeList(){ final ProgressDialog pDialog = new ProgressDialog(this); pDial
private void getEventTypeList(){
final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
// JSONObject jsonObject = null;
JSONObject jsonObject = new JSONObject();
CustomJSONObjectRequest jsonObjectRequest = new CustomJSONObjectRequest(Request.Method.POST, Constants.EVENT_TYPE_LIST_URL, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Utility.showLogError(PostRequirParty.this, "GetEventTypeListResponse" + response.toString());
DataBean bean = new DataBean();
bean = parser.getEventTypeList(response);
eventBeansList = new ArrayList<EventTypeBean>();
eventBeansList = bean.getEventTypeList();
eventNamesArr = new String[eventBeansList.size()];
for (int i = 0; i < eventBeansList.size(); i++) {
eventNamesArr[i] = eventBeansList.get(i).getEvent_type_name();
}
// hiding progressDialog
pDialog.hide();
ArrayAdapter<String> eventTypeAdapter = new ArrayAdapter<String>(PostRequirParty.this, R.layout.spinner_item, eventNamesArr);
eventTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
event.setAdapter(new NothingSelectedSpinnerAdapter(eventTypeAdapter, R.layout.spinner_row_nothing_selected, PostRequirParty.this));
//event.setPrompt("Select");
event.setAdapter(eventTypeAdapter);
final DataBean finalBean = bean;
event.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
event_id = finalBean.getEventTypeList().get(position).getEvent_type_id();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pDialog.hide();
Utility.showToastMsg(PostRequirParty.this, error.getMessage());
}
});
Utility.showLogError(PostRequirParty.this, "GetEventTypeList URL = " + Constants.EVENT_TYPE_LIST_URL);
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
}
private void getEventTypeList(){
final ProgressDialog pDialog=新建ProgressDialog(本);
设置消息(“加载…”);
pDialog.show();
//JSONObject JSONObject=null;
JSONObject JSONObject=新的JSONObject();
CustomJSONObjectRequest jsonObjectRequest=新建CustomJSONObjectRequest(Request.Method.POST,Constants.EVENT\u TYPE\u LIST\u URL,jsonObject,new Response.Listener()){
@凌驾
公共void onResponse(JSONObject响应){
showLogError(PostRequirParty.this,“GetEventTypeListResponse”+response.toString());
DataBean=newDataBean();
bean=parser.getEventTypeList(响应);
eventBeansList=新的ArrayList();
eventBeansList=bean.getEventTypeList();
eventNamesArr=新字符串[eventBeansList.size()];
对于(int i=0;i
这是我的解析代码:
public DataBean getEventTypeList(JSONObject response) {
DataBean dataBean = new DataBean();
ArrayList<EventTypeBean> eventTypeList = new ArrayList<EventTypeBean>();
if (response != null){
try{
JSONArray jsonArray = response.getJSONArray(Constants.DATA);
for (int i = 0; i < jsonArray.length(); i++) {
EventTypeBean typeBean = new EventTypeBean();
typeBean.setEvent_type_id(jsonArray.getJSONObject(i).getString(Constants.EVENT_TYPE_ID));
typeBean.setEvent_type_name(jsonArray.getJSONObject(i).getString(Constants.EVENT_TYPE_NAME));
eventTypeList.add(typeBean);
}
}catch (JSONException e){
e.printStackTrace();
}
dataBean.setEventTypeList(eventTypeList);
}
return dataBean;
}
公共数据库getEventTypeList(JSONObject响应){
DataBean DataBean=新的DataBean();
ArrayList eventTypeList=新建ArrayList();
if(响应!=null){
试一试{
JSONArray JSONArray=response.getJSONArray(Constants.DATA);
for(int i=0;i
在服务器端检查-使用的url配置和方法类型。@Mahalakshmi但第一个API正在工作,如果我想在程序中更改的地方使用第一个API?您得到的响应代码是什么?您在jsonObject中发送的是什么?我猜您没有在请求结构中发送任何数据//在这段代码之后,写下面的代码。jsonObject.put(“getEventTypeList”,jsonObject.toString());(或)jsonObject.put(“getEventTypeList”,即“”);