0

我在尝试从中读取时收到此错误JObjectC#PHP是基本查询的结果"SELECT * FROM items"...

Unexpected character encountered while parsing value: S. Path '', line 0, position 0.

PHP

$query = ($_POST["test"]);

if ($result = $mysqli->query($query)
{
    $jsonResult = json_encode($result);
}   

echo $jsonResult;

C#

public JObject GetThat()
{
    HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();

    Stream Answer = WebResp.GetResponseStream();

    string phpResponse = Answer.ToString();
    JObject myResult = JObject.Parse(phpResponse);

    return myResult;
}

我究竟做错了什么?谢谢。

4

2 回答 2

2

问题是它Answer.ToString()不会将流内容作为字符串返回。尝试这样的事情。

public JObject GetThat()
{
    HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();

    string phpResponse = string.Empty;
    using(StreamReader rdr = new StreamReader(WebResp.GetResponseStream()))
        phpResponse = rdr.ReadToEnd();
    }

    JObject myResult = JObject.Parse(phpResponse);

    return myResult;
}
于 2012-07-13T14:07:29.267 回答
0

原来问题出在数组类型上。

$row = $result->fetch_array(MYSQLI_NUM);

不起作用,但是

$row = $result->fetch_array(MYSQLI_BOTH);

$row = $result->fetch_array(MYSQLI_ASSOC);

做。有谁知道为什么?谢谢。

于 2012-07-15T18:00:50.113 回答