Java 使用截击的字符串请求

Java 使用截击的字符串请求,java,android,json,Java,Android,Json,我正试图从你那里获取加密硬币的数据 Coins.java public class coins extends AppCompatActivity { List<coinlist> coinList; ListView listView; TextView empty; //String coin_name,symbol; //Double price,market_cap,tot_marketcap,port,onehour,sevendays,twenty4hour,coin;

我正试图从你那里获取加密硬币的数据

Coins.java

public class coins extends AppCompatActivity {
List<coinlist> coinList;
ListView listView;
TextView empty;
//String coin_name,symbol;
//Double price,market_cap,tot_marketcap,port,onehour,sevendays,twenty4hour,coin;
DecimalFormat df = new DecimalFormat("###,###,###,###,###.##");
final Context mContext = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_coins);
    setTitle("Coins");
    listView = (ListView) findViewById(R.id.list_alts);
    coinList = new ArrayList<>();
    empty = (TextView) findViewById(R.id.alt_empty);
    listfill();
    //coinList.add(new ico(c.getString(0), c.getString(3), c.getString(4), c.getDouble(1), c.getDouble(2),c.getDouble(5),df.format(prof)));
    if(coinList.isEmpty()){
        listView.setVisibility(View.GONE);
        empty.setVisibility(View.VISIBLE);
    }
    else {
        MyAltsAdapter adapter = new MyAltsAdapter(this, R.layout.list_alts, coinList);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView TV_name = (TextView) view.findViewById(R.id.name);

                //String name = TV_name.getText().toString();
                //Intent intent = new Intent(coins.this, personalView.class);
                //intent.putExtra(itemname, name);
                //startActivity(intent);
            }
        });
    }

}

private void listfill() {

    String URL_ROOT = GlobalClass.API_URL;

    RequestQueue queue = Volley.newRequestQueue(this);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_ROOT, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            if (response != null) {
                System.out.println(response);
            }
            try {
                JSONArray jsonArray = new JSONArray(response);

                JSONObject jsonObject = jsonArray.getJSONObject(0);
                String code = jsonObject.getString("Response");
                if (code.equals("Success")) {
                    Toast.makeText(coins.this, "Success", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(coins.this, code, Toast.LENGTH_SHORT).show();
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }


        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    System.out.println(String.valueOf(volleyError));

                }
            }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            // return super.getParams();
            Map<String, String> params = new HashMap<String, String>();
            return super.getParams();
        }
    };
    queue.add(stringRequest);
   // Controller.getPermission().addToRequestQueue(stringRequest);
    }
}
public-class活动{
列表列表;
列表视图列表视图;
文本视图为空;
//字符串硬币的名称、符号;
//双倍价格、市值、总市值、港口、一小时、七天、二十四小时、硬币;
DecimalFormat df=新的DecimalFormat(“#####,###,###,####,####,####”);
最终上下文mContext=此;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_);
设定所有权(“硬币”);
listView=(listView)findViewById(R.id.list\u alts);
coinList=新的ArrayList();
empty=(TextView)findViewById(R.id.alt_empty);
listfill();
//添加(新的ico(c.getString(0)、c.getString(3)、c.getString(4)、c.getDouble(1)、c.getDouble(2)、c.getDouble(5)、df.format(prof));
if(coinList.isEmpty()){
setVisibility(View.GONE);
empty.setVisibility(View.VISIBLE);
}
否则{
MyAltsAdapter adapter=新的MyAltsAdapter(this,R.layout.list\u alts,coinList);
setAdapter(适配器);
setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
TextView TV_name=(TextView)view.findViewById(R.id.name);
//String name=TV_name.getText().toString();
//意向意向=新意向(coins.this、personalView.class);
//意向。putExtra(项目名称、名称);
//星触觉(意向);
}
});
}
}
私有void listfill(){
字符串URL\u ROOT=GlobalClass.API\u URL;
RequestQueue=Volley.newRequestQueue(this);
StringRequest StringRequest=新的StringRequest(Request.Method.POST,URL\u ROOT,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
if(响应!=null){
System.out.println(响应);
}
试一试{
JSONArray JSONArray=新JSONArray(响应);
JSONObject JSONObject=jsonArray.getJSONObject(0);
字符串代码=jsonObject.getString(“响应”);
如果(代码等于(“成功”)){
Toast.makeText(coins.this,“Success”,Toast.LENGTH_SHORT).show();
}否则{
Toast.makeText(coins.this,code,Toast.LENGTH_SHORT).show();
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
},
新的Response.ErrorListener(){
@凌驾
公共错误响应(截击错误截击错误){
System.out.println(String.valueOf(volleyError));
}
}) {
@凌驾
受保护的映射getParams()引发AuthFailureError{
//返回super.getParams();
Map params=新的HashMap();
返回super.getParams();
}
};
添加(stringRequest);
//Controller.getPermission().addToRequestQueue(stringRequest);
}
}
这就是我得到的错误:

 02-11 19:05:11.740 32158-32158/com.example.nikko.icopersonal W/System.err: org.json.JSONException: Value {"Response":"Success","Message":"Coin list succesfully returned! This api is moving to https:\/\/min-api.cryptocompare.com\/data\/all\/coinlist, please change the path.","BaseImageUrl":"https:\/\/www.cryptocompare.com",...**(its really big)**
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at org.json.JSONArray.<init>(JSONArray.java:96)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at org.json.JSONArray.<init>(JSONArray.java:108)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at com.example.nikko.icopersonal.coins$2.onResponse(coins.java:85)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at com.example.nikko.icopersonal.coins$2.onResponse(coins.java:78)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at android.os.Handler.handleCallback(Handler.java:769)
02-11 19:05:11.759 32158-32158/com.example.nikko.icopersonal W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:98)
02-11 19:05:11.760 32158-32158/com.example.nikko.icopersonal W/System.err:     at android.os.Looper.loop(Looper.java:164)
02-11 19:05:11.760 32158-32158/com.example.nikko.icopersonal W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6540)
02-11 19:05:11.760 32158-32158/com.example.nikko.icopersonal W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
02-11 19:05:11.760 32158-32158/com.example.nikko.icopersonal W/System.err:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
02-11 19:05:11.760 32158-32158/com.example.nikko.icopersonal W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
02-11 19:05:11.768 32158-32158/com.example.nikko.icopersonal D/Volley: [2] Request.finish: 3333 ms: [ ] https://min-api.cryptocompare.com/data/all/coinlist 0x3504fd88 NORMAL 1
02-11 19:05:11.740 32158-32158/com.example.nikko.icoppersonal W/System.err:org.json.JSONException:Value{“Response”:“Success”,“Message”:“Coin list已成功返回!此api正在移动到https:\/\/min api.cryptocompare.com\/data\/all\/coinlist,请更改路径。”,“BaseImageUrl:“https:\/\/www.cryptocompare.com”**(它真的很大)**
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at org.json.json.typemissmatch(json.java:111)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:org.json.JSONArray.(JSONArray.java:96)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:org.json.JSONArray.(JSONArray.java:108)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at com.example.nikko.icoppersonal.coins$2.onResponse(coins.java:85)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at com.example.nikko.icoppersonal.coins$2.onResponse(coins.java:78)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at android.os.Handler.handleCallback(Handler.java:769)
02-11 19:05:11.759 32158-32158/com.example.nikko.icoppersonal W/System.err:at-android.os.Handler.dispatchMessage(Handler.java:98)
02-11 19:05:11.760 32158-32158/com.example.nikko.icoppersonal W/System.err:at-android.os.Looper.loop(Looper.java:164)
02-11 19:05:11.760 32158-32158/com.example.nikko.icoppersonal W/System.err:位于android.app.ActivityThread.main(ActivityThread.java:6540)
02-11 19:05:11.760 32158-32158/com.example.nikko.icoppersonal W/System.err:at java.lang.reflect.Method.invoke(本机方法)
02-11 19:05:11.760 32158-32158/com.example.nikko.icoppersonal W/System.err:at com.android.internal.os.zyote$MethodAndArgsCaller.run(zyote.java:240)
02-11 19:05:11.760 32158-32158/com.example.nikko.icoppersonal W/System.err:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
02-11 19:05:11.768 32158-32158/com.example.nikko.icod/Volley:[2]Request.finish:3333 ms:[]https://min-api.cryptocompare.com/data/all/coinlist 0x3504fd88正常1
我认为这与我接受字符串请求而不是jsonArrayR有关
JSONObject jsonObject = new JSONObject(response);
//String code = jsonObject.getString("Response");
// or better
String code = jsonObject.optString("Response","");