添加字符串时,我在 MediaType OkHttp3 中得到 null

When adding String I get null in MediaType OkHttp3

为什么我得到的是空值?为什么传输的是 phone 数字,而不是通常的字符串? 我整天都在处理这个问题,请帮忙。

firstName_str = firstName.getText().toString();
ip_str = ip;
lastName_str = lastName.getText().toString();
email_str = email.getText().toString();
getPhoneNumber_str = firebaseAuth.getCurrentUser().getPhoneNumber();
getPhoneNumber_str = getPhoneNumber_str.replace("+", "");
Log.d("ccp_str2", "firstName_str: " + firstName_str);
Log.d("ccp_str2", "ip_str: " + ip_str);
Log.d("ccp_str2", "lastName_str: " + lastName_str);
Log.d("ccp_str2", "email_str: " + email_str);
Log.d("ccp_str2", "getPhoneNumber_str: " + getPhoneNumber_str);

MediaType JSON = MediaType.parse("application/json; charset=utf-8");
String json = "{\n    \"ai\": \"222222\",\n    \"ci\": \"111\",\n    \"gi\": \"111\",\n    \"userip\": "+ip_str+",\n    \"firstname\": "+firstName_str+",\n    \"lastname\": "+lastName_str+",\n    \"email\": "+email_str+",\n    \"password\": \"Aa12345!\",\n    \"phone\": "+getPhoneNumber_str+",\n \"so\":\"start\"\n}";

RequestBody body = RequestBody.create(JSON, json);

OkHttpClient client = new OkHttpClient().newBuilder()
        .build();
Request request = new Request.Builder()
        .url("https://platform.link.com/api/signup/procform")
        .method("POST", body)
        .addHeader("x-trackbox-username", "name")
        .addHeader("x-trackbox-password", "pass")
        .addHeader("x-api-key", "key")
        .addHeader("Content-Type", "application/json")
        .build();
Response response = client.newCall(request).execute();
String str_leads = response.body().string();
Log.d("str_leads", "str_leads: " + str_leads);

日志ccp_str2:

ccp_str2: firstName_str: TestName
ccp_str2: ip_str: 111.111.111.111
ccp_str2: lastName_str: TestLast
ccp_str2: email_str: test@gmail.com
ccp_str2: getPhoneNumber_str: 441234567890

日志str_leads:

str_leads: {"status":false,"data":"IP is not valid","addonData":{"ai":"222222","ci":"111","gi":"111","userip":null,"firstname":null,"lastname":null,"email":null,"password":"Aa12345!","phone":441234567890,"so":"start"}}

这部分:

\"phone\": "+getPhoneNumber_str+",\n

需要:

\"phone\": \""+getPhoneNumber_str+"\",\n

您需要在变量之间创建转义引号才能正确串联。