【发布时间】:2019-08-14 16:04:35
【问题描述】:
我有一个基于用户键入的关键字返回的 JSON 对象。它只返回用户输入的一些关键字。当我检查邮递员并输入相同的关键字时,它会正确返回。
引发以下异常:
Newtonsoft.Json.JsonSerializationException:
Must specify valid information for parsing in the string
JSON
{
"valid": true,
"result": {
"points": [
{
"pointId": "505",
"name": "Building one",
"description": "Office of Technology and Data Application Development",
"latitude": "xxx",
"longitude": "xxx",
"floor": "B",
"aliases": [],
"comments": [],
"images": []
}
],
"categories": []
},
"errors": []
}
模型类
public class SearchPoints
{
public bool Valid { get; set; }
public Result Result { get; set; }
public List<string> Errors { get; set; }
}
public class Result
{
public List<Point> Points { get; set; }
public List<Category> Categories { get; set; }
}
public class Category
{
public long CategoryId { get; set; }
public string Name { get; set; }
public long ParentId { get; set; }
public string Parent { get; set; }
}
public class Point
{
public long PointId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public Floor Floor { get; set; }
public List<string> Aliases { get; set; }
public List<string> Comments { get; set; }
public List<string> Images { get; set; }
}
public enum Floor
{
A,
B
};
服务方式
var apiResponse = await _httpClient.GetAsync(Url + _keyword);
var apiContent = apiResponse.Content.ReadAsStringAsync().Result;
var pointsJsonResponse = JsonConvert.DeserializeObject<SearchPoints>(apiContent);
var potentialPoints = new ObservableCollection<Point>(pointsJsonResponse.Result.Points);
PointsItemSource = potentialPoints;
【问题讨论】:
-
您是否将代码中返回的原始 json 与邮递员进行了比较?它们是相同的还是不同的?如果它们不同,那么您发布的所有代码都与解决问题无关。
-
是的,我比较了它们,它们是相同的。
-
所以当你反序列化时,只是缺少一些项目?多少?有什么规律吗?
-
@Anthony 您如何发送键入的关键字?当用户输入或他们有一个提交按钮可以点击?
-
他们没有多少失踪,我不认为有一个模式。我怎么知道有些缺失是当我在邮递员中测试相同的关键字时,我得到了正确的列表,但是当我用应用程序测试时,我没有
标签: c# xamarin.forms json.net