【发布时间】:2016-06-23 20:53:34
【问题描述】:
从 JsonReader 读取 JObject 时出错。路径'',第 3 行,位置 1。
知道为什么会这样吗?当我使用完全相同的代码并将其发送到解析(例如)时它可以工作,但是当我尝试将它发送到我自己的域时它不起作用。这个后端有关系吗?
static public async Task<JObject> signupUser(string username, string password)
{
var httpClientRequest = new HttpClient ();
var postData = new Dictionary <string, string> ();
postData.Add ("username", username);
postData.Add ("password", password);
var jsonRequest = JsonConvert.SerializeObject(postData);
HttpContent content = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");
var result = await httpClientRequest.PostAsync("http://myadress.com/_put.php", content);
var resultString = await result.Content.ReadAsStringAsync ();
System.Diagnostics.Debug.WriteLine (resultString);
var jsonResult = JObject.Parse (resultString);
return jsonResult;
System.Diagnostics.Debug.WriteLine (jsonResult);
}
我的后端代码:
<?php
$value = json_decode(file_get_contents('php://input'));
$mysql_pekare= new mysqli ("serv", "user","pass", "db");
if(!empty($value)) {
$stmt = $mysql_pekare->prepare("INSERT INTO users (`username`, `password`) VALUES(?,?)");
$stmt->bind_param("ss", $value->username, $value->password);
$stmt->execute();
$stmt->close();
$mysql_pekare->close();
}
?>
【问题讨论】:
-
那么
resultString中有什么? -
秒在我的日志中运行它
-
当我在日志中运行它时,它内部似乎“什么都没有”,或者它在有机会在日志中给出结果之前就崩溃了。 var jsonResult = JObject.Parse (resultString);是使整个事情崩溃的代码
-
嗯,是的,您似乎没有记录
resultString... 为什么不直接在调试器中运行代码,然后看看呢? -
我刚刚添加了它。 System.Diagnostics.Debug.WriteLine (resultString);如果这就是你的意思。
标签: c# json xamarin xamarin.forms