这是我获取数据的地方。
$contacts = array();
while ($row = mysqli_fetch_array($stmt))
{
$contact = array("ID" => $row['ProduktID'],
"Name" => $row['ProduktNamn'],
"Number" => $row['ProduktPris']);
array_push($contacts, $contact);
}
echo json_encode(array('results' => $contacts), JSON_PRETTY_PRINT);
现在,当我在Xamarin的代码中使用它时,我可以在日志中写出整个内容,但是当我尝试写出某个表的某个“名称”时却没有。这是代码:
static public async Task<JObject> getOurMainInfo()
{
var httpClientRequest = new HttpClient ();
var result = await httpClientRequest.GetAsync ("http://localhost/getmystuff.php");
var resultString = await result.Content.ReadAsStringAsync ();
var jsonResult = JObject.Parse (resultString);
// var jsonResult = JsonConvert.DeserializeObject<Contact>(resultString); //Should I implement this somehow to my JObject? Contact is my public class.
System.Diagnostics.Debug.WriteLine (jsonResult["Name"]); //i get nothing in the log. if i remove ["Name"] i get the entire data in the log.
return jsonResult;
}
我的公共课(如果我需要这个以某种方式连接和使用edatbase):
public class Contact
{
public string ID { get; set; }
public string Name { get; set; }
public string Number { get; set; }
}