如何在Android中使用此格式创建JSON:由于我将传递的API将解析JsonArray然后解析对象.或者只是传递一个json对象会没关系吗?因为我只需要为每个服务调用插入1个事务.
{
"student": [
{
"id": 1,
"name": "John Doe",
"year": "1st",
"curriculum": "Arts",
"birthday": 3/3/1995
},
{
"id": 2,
"name": "Michael West",
"year": "2nd",
"curriculum": "Economic",
"birthday": 4/4/1994
}
]
}
Run Code Online (Sandbox Code Playgroud)
我所知道的只是JSONObject.像这个.
JSONObject obj = new JSONObject();
try {
obj.put("id", "3");
obj.put("name", "NAME OF STUDENT");
obj.put("year", "3rd");
obj.put("curriculum", "Arts");
obj.put("birthday", "5/5/1993");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗.谢谢
我正在使用volley进行json解析.我想使用POST向服务器端发送一些数据.我想发送.现在任何人都可以告诉我如何将过滤器阵列发送到服务器?
以下是我的代码段.我也尝试Hashmap和Jsonobject.但得到这个错误.
错误:
org.json.JSONException: Value at Data of type java.lang.String cannot be converted to JSONObject
Run Code Online (Sandbox Code Playgroud)
格式
{
"typeName": "MANUFACTURER",
"typeId": 22,
"cityId": 308,
"sortBy": "productname",
"sortOrder": "desc",
"filter":[
{
"filterId":101,
"typeName":"CAT_ID",
"filterId":102,
"typeName":"CAT_ID"
}
]
}
Run Code Online (Sandbox Code Playgroud)
对于Code Check pastie