关于在Swift中更改参数值的问题

时间:2019-08-05 02:42:44

标签: swift

我正在使用应用程序/ x-www-form-urlencoded处理POST请求。在指定要使用Alamofire传递的参数的过程中存在一个问题。

我创建了一个名为passingParameter的参数变量 我想在创建user_id时更改参数。

var passingParameter = [
        "user_id" : "null",
        "user_email" : "null",
        "user_age" : "null",
        "user_gender" : "null",
        "user_birthday" : "null",
        "user_type" : "google"
    ]

如何在passingParameter变量中添加ID?

ex)

var passingParameter = [
        "user_id" : "1122445566",
        "user_email" : "null",
        "user_age" : "null",
        "user_gender" : "null",
        "user_birthday" : "null",
        "user_type" : "google"
    ]

1 个答案:

答案 0 :(得分:0)

很难说出这里的要求。

如果某个地方已经有public class User { private int id; private String name; private String urlPicture; private Address address; // getters and setters } public class Address { private String country; // getters and setters } public void testResponse(){ RestTemplate restTemplate = new RestTemplate(); Data data = new Data(); User user = new User(); Gson gson = new Gson(); String response = restTemplate.getForObject( "https://apifrommyrequest.com/user/{id}", String.class, 73442); data = gson.fromJson(response, Data.class); System.out.println(data); } 变量,可以说

user_id

然后,您可以在创建时简单地分配值。

var userID = "1122445566"

或以后的

var passingParameter = [
        "user_id" : userID,
        "user_email" : "null",
        "user_age" : "null",
        "user_gender" : "null",
        "user_birthday" : "null",
        "user_type" : "google"
    ]