And*_*ler 11 java android json
我正在尝试为POST请求编码此字符串.任何人都可以告诉我如何编码
{"jsonrpc": "2.0", "method": "Files.GetSources", "params":{"media":"music"}, "id": 1}
Run Code Online (Sandbox Code Playgroud)
到目前为止我有
JSONOjbect obj = new JSONObject();
obj.put("jsonrpc", "2.0");
obj.put("method", "Files.GetSources");
Run Code Online (Sandbox Code Playgroud)
但是我不知道怎么放其余的 - 有人可以帮忙吗?
Rob*_*ska 25
如果你问如何将嵌套params对象放在那里,你可能会这样做:
JSONObject params = new JSONObject();
params.put("media", "music");
obj.put("params", params);
Run Code Online (Sandbox Code Playgroud)
要使用数组(根据下面的评论),你可以这样做:
JSONArray properties = new JSONArray();
properties.put("resume");
properties.put("genre");
properties.put("studio");
...
JSONObject params = new JSONObject();
params.put("properties", properties);
obj.put("params", params);
Run Code Online (Sandbox Code Playgroud)