Volley:在JSONObject中使用List <t>发出请求

时间:2015-09-19 05:52:01

标签: android android-volley jsonobject

我使用df1 <- structure(list(Col1 = c("China", "Japan", "US", "Canada")), .Names = "Col1", class = "data.frame", row.names = c(NA, -4L)) 并需要发送到服务器对象列表#include<iostream> int main(){ std::string s = " α a "; std::cout << "s = " << s << std::endl; for(std::string::iterator c = s.begin(); c != s.end(); ++c){ if(*c == 'a') std::cout << "letter a" << std::endl; // ok if(*c == 'α') std::cout << "greek letter alpha" << std::endl; // error: character too large std::cout << *c << std::endl; } return 0; } Volley

User上课:

List<Integer>

我使用代码

User

问题是JSONObject无法解析public class User { public int id; public String name; public MyClass(int id, String name){ this.id = id; this.name= name; } }

    HashMap<String, Object> params = new HashMap<>();

    List<Integer> categories = new ArrayList<>(Arrays.asList(5, 8, 9));
    List<User> users = new ArrayList<>(Arrays.asList(
            new User(1, "User1"),
            new User(2, "User2"),
            new User(3, "User3")
    ));


    params.put("categories", categories);
    params.put("users", users);

    JSONObject jsonBody = new JSONObject(params);

如何使用User解析它?

参数“{ "users": [ null, null, null ], "categories": [ 5, 8, 9 ] } ”应为JSONObject而不是users

我需要array,因为string使用它

JSONObject

enter image description here

完整代码:

Volley

0 个答案:

没有答案