不知道为什么案例2不能 final JSONObject body = new JSONObject();
try {
// Todo: populate JSON body
} catch (JSONException e) {
e.printStackTrace();
}
StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://...",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
) {
@Override
public byte[] getBody() throws AuthFailureError {
return body.toString().getBytes();
}
@Override
public String getBodyContentType() {
return "application/json";
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
Split
到str
和a
b
答案 0 :(得分:7)
new char['\\']
是一个大小为92的字符数组。这是由于从char
到int
的隐式转换:
int number = '\\'; // number is 92
char[] array = new char['\\']; // char array of size 92 with default values
这就像你写的那样:
var result = str.Split(new char[92]);
单个字符数组的编写方式如下:
var result = str.Split(new char[] { '\\' });
答案 1 :(得分:3)
这是因为new char['\\']
创建了(int)'\\'
长度的字符数组。如果你想要一个具有给定值的数组,如果你认为它足够可读,你可以new char[] { '\\' }
甚至new[] { '\\' }
答案 2 :(得分:0)
这样做:
string str = @"a\b";
String[] result = str.Split('\\'); // work (case 1)
答案 3 :(得分:0)
new char[]
是一个数组。使用
var result = str.Split(new char[] { '\\' });