我正在尝试用我的用户数据填充listview。我有自定义的php api,它的有效json.I检查但数据总是返回null。
async public Task<List<User>> userAll(string connUrl)
{
client.BaseAddress = new Uri(connUrl);
var response = await client.GetAsync("api/?auth=6911B6676F7311E174A9F2CE3B7086E029F9975C29E81E87B162B21BF065C9A76619E4993D243FF7A66723B07F3EF6967B5461AE89FD48BD005E72B4046F6273");
var jsondata = response.Content.ReadAsStringAsync().Result;
var root = JsonConvert.DeserializeObject<List<User>>(jsondata);
return root;
}
我的用户类别
public class User
{
public string users_id { get; set; }
public string users_name { get; set; }
public string users_password { get; set; }
public string users_mail { get; set; }
}
我的观看代码
private async void get_data_clicked(object sender, EventArgs e)
{
var res = await con.userAll(url);
listfills.ItemsSource = res;
}
我的Json数据
[{"users_id":"1","users_name":"admin","users_password":"C7AD44CBAD762A5DA0A452F9E854FDC1E0E7A52A38015F23F3EAB1D80B931DD472634DFAC71CD34EBC35D16AB7FB8A90C81F975113D6C7538DC69DD8DE9077EC","users_mail":"123@gmail.com"},{"users_id":"2","users_name":"123","users_password":"C7AD44CBAD762A5DA0A452F9E854FDC1E0E7A52A38015F23F3EAB1D80B931DD472634DFAC71CD34EBC35D16AB7FB8A90C81F975113D6C7538DC69DD8DE9077EC","users_mail":"1234@gmail.com"}]
我的php API
header('Content-type: application/json');
create_json();
function create_json()
{
$auth = $_GET['auth'];
if ($auth == "6911B6676F7311E174A9F2CE3B7086E029F9975C29E81E87B162B21BF065C9A76619E4993D243FF7A66723B07F3EF6967B5461AE89FD48BD005E72B4046F6273")
{
$getData = @mysql_query("select * from brlcglrx_users ");
$json_array = array();
while( $data_from_db = @mysql_fetch_array($getData, MYSQL_ASSOC))
{
$json_array[] = $data_from_db;
}
echo json_encode($json_array, JSON_UNESCAPED_UNICODE);
if (empty($json_array))
{
echo "Something goes wrong...";
}
}
}