我有,我想轉換到一個列表此JSON值轉換的JSONObject列出<T>
[{
"id_cuenta": 1,
"nombre": "Mercedes Luj\u00e1n",
"apellido": "Llano",
"ci": 123,
"telefono": 123456789,
"dispositivo_id": "355790037549877",
"password": "holaa",
"created_at": "2016-07-02 11:36:57",
"updated_at": "2016-07-09 09:56:53"
}]
這是到目前爲止我的代碼:
private List<cuentaObtener> mCuenta;
btnLogIn.Click += async(object sender, EventArgs e) =>
{
string url = "http://localhost:8000/api/v1/cuenta_ci/" + ci.Text + "";
JsonValue json = await ObtenerCi(url);
private async Task<JsonValue> ObtenerCi(string url)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.ContentType = "application/json";
request.Method = "GET";
// Send the request to the server and wait for the response:
using (WebResponse response = await request.GetResponseAsync())
{
// Get a stream representation of the HTTP web response:
using (Stream stream = response.GetResponseStream())
{
// Use this stream to build a JSON document object:
JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
//Code to convert JsonObject to List<T>
// Return the JSON document:
return jsonDoc;
}
}
這是我的課,我想店面價值:
public class cuentaObtener
{
public int id_cuenta { get; set; }
public string nombre { get; set; }
public string apellido { get; set; }
public int ci { get; set; }
public int telefono { get; set; }
public string dispositivo_id { get; set; }
public string password { get; set; }
}
我該如何做到這一點?先謝謝你!
'jsonDoc.Cast()'...或者,你知道,'JsonConvert.DeserializeObject <名單>(jsonString)',在那裏你閱讀使用'HttpClient'的'jsonString',而不是過時的'HttpWebRequest'。 –
CodeCaster
更改的HttpWebRequest到的HttpClient和我有這樣的錯誤=「System.Net.HttpWebRequest」不包含一個定義‘的GetResponse’和沒有擴展方法‘的GetResponse’接受型的第一參數‘System.Net.HttpWebRequest’可以是(是否缺少using指令或程序集引用「 – meluluji
使用HttpClient的是一個明智的建議謝謝:) – meluluji