// JSON object to hold the information, which is sent to the server
JSONObject jsonObjSend = new JSONObject();
jsonObjSend.put("action", "myAction");
jsonObjSend.put("type", tipo);
Run Code Online (Sandbox Code Playgroud)
现在一切都好,但如果我想添加
jsonObjSend.put("elementi", arrayOfElements);
Run Code Online (Sandbox Code Playgroud)
其中arrayOf Elements必须是字符串数组.我能怎么做?
/ **编辑
我需要什么样的例子
{
"action": "myAction",
"type": "elementi",
"elementi": [
"3287498357",
"23472857"
]
}
Run Code Online (Sandbox Code Playgroud) 我必须要求使用Volley Framework.这是一个带有JSONObject的POST请求.
我必须传递一个字符串和一个JSONArray ..但我怎么能?
我从这开始:
private String mUrl;
private ArrayList<String> mUrlDove;
HashMap<String, String> params = new HashMap<String, String>();
params.put("url", mUrl);
params.put("urlDove", mUrlDove); ---> Wrong because mUrlDove is not a String
mUrl = app.getInstance().getmUrlRestWS() + getString(R.string.path);
JsonObjectRequest mRequest = new JsonObjectRequest(
mUrl, new JSONObject(params),
createMyReqSuccessListener(),
createMyReqErrorListener()) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return app.getInstance().createBasicAuthHeader();
}
};
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用浏览器,我必须设置:
{
"url": "www.secret.com",
"urlDove" : [ "www.google.com","www.yahoo.com"]
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,它将大量数据发送到server.Now我想使用volley发送一个params数组到php页面.但是我无法发送它.
将params添加为Array的代码.
String[] arr =new String[7];
for(int i=1;i<=7;i++)
{
arr[i]="questionId_"+i+"_"+"ans_"+i;
}
HashMap<String ,String[]> params=new HashMap<String, String[]>(7);
params.put("params", arr);
Run Code Online (Sandbox Code Playgroud)
向服务器发出请求的代码
RequestQueue que=Volley.newRequestQueue(this);
final ProgressDialog dialog = new ProgressDialog(HealthMyHistory.this);
dialog.setTitle("Please Wait");
dialog.setMessage("Sending Data");
dialog.setCancelable(false);
dialog.show();
CustomJobjectRequest jsObjRequest = new CustomJobjectRequest(Method.POST, url, params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response)
{
dialog.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError response) {
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Unable to Send Data!"+" "+response.toString(), Toast.LENGTH_SHORT).show();
}
});
que.add(jsObjRequest);
}
Problem is in CustomJobjectRequest there is no …Run Code Online (Sandbox Code Playgroud)