UWP以HTML格式获取数据,但不是JSON

时间:2016-05-18 17:00:30

标签: c# php json uwp

我试图从php文件中获取一些json数据。 但程序将(response2)中的数据作为HTML内容获取,而不是json

Uri geturi2 = new Uri(JSON_GetHASSCENE_URL + "&FilmID=" + film.id);
using (HttpClient client2 = new HttpClient())
{
//MultipartFormDataContent content = new MultipartFormDataContent();
HttpResponseMessage responseGet2 = await client2.GetAsync(geturi2);
string response2 = await responseGet2.Content.ReadAsStringAsync();
JObject token2 = JObject.Parse(response2);
List<HasScene> result = JsonConvert.DeserializeObject<List<HasScene>>(response2);
}

问题可能来自php文件。所以,我添加了标题,但问题没有解决。 这是php文件

<?php
header('Content-Type: application/json');
//set vars
$filmID = (int)$_GET['FilmID'];

try {
    $conn = new PDO('mysql:host=localhost;dbname=********','*****','*********');
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}
catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

//Create SELECT query
$qry = $conn->prepare("SELECT * FROM Film WHERE FilmID=? ");
$qry->bindParam(1, $filmID);

//Check whether the query was successful or not
if($qry->execute()){
    $count = $qry->rowCount();
}

$json_data=array();//create the array

if($count >0) {

    foreach($qry as $rec)//foreach loop
    {

        // all table's columns must be implemented here

        //$json_array['id']=$rec['id'];
        $json_array['FilmID']=$rec['FilmID'];
        $json_array['IsHasScene']=$rec['HasScene'];

        //here pushing the values in to an array
        array_push($json_data,$json_array);

    }

}

echo json_encode($json_data);
?>

(response2)变量的结果如下所示

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head profile=\"http://gmpg.org/xfn/11\">\n        <meta http-equi..."

对此有何帮助?

由于

1 个答案:

答案 0 :(得分:0)

我刚刚发现了这个问题,它就在链接中 我刚换了“&amp;”用“?”。它运作良好