我正在从事 Xamarin 项目。基本上,我想从 API 接收数据并显示它。为此,我正在使用 RestSharp。
这是我的 API 请求代码。
string test;
test = "yAHO0SsAmjJi1qTZGcK3sMHHIhWTN4Yq";
string s = string.Format("http://192.168.1.4:3116/api/user/getuser/{0}", test);
client = new RestClient(s);
request = new RestRequest(Method.GET);
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Content-Type", "application/json");
IRestResponse response2 = client.Execute(request);
Run Code Online (Sandbox Code Playgroud)
这是我收到的 JSON 对象。
{
"id": 1,
"token": "yAHO0SsAmjJi1qTZGcK3sMHHIhWTN4Yq",
"email": "some email",
"password": "testpassword",
"currentCompany": "some company",
"currentRole": "Software Developer",
"date": "Something",
"name": "Some name",
"lastName": "Some surname",
"headLine": "Some text",
"education": "University of Hotshots",
"country": "Who cares",
"imageLocation": "Some url"
}
Run Code Online (Sandbox Code Playgroud)
这是我使用网站为它创建的类:json2csharp.com/
class User
{ …Run Code Online (Sandbox Code Playgroud)