請幫我看看我是新的xamarin.forms和C#我嘗試了每個解決方案都是在計算器中給出,但無法解決無法反序列化當前的JSON對象(例如{「name」:「value」})
using (var httpClient = new HttpClient())
{
var response = httpClient.GetAsync(Url).Result;
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
string contents = await responseContent.ReadAsStringAsync();
List<abcModel> tm = JsonConvert.DeserializeObject<List<abcModel>>(contents);
abcMaster = new ObservableCollection<SummaryModel>();
var c = tm[0].SSum.Count();
}
}
型號
public class abcModel
{
public List<SSum> SSum { get; set; }
}
public class SSum
{
public string Name{ get; set; }
}
的json
{"a":[{"SSum":[{"Name":"Earth"}]}]}
錯誤: -
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[abcModel]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
IM嘗試計數SSUM部分內部存在的JSON總價值如何,我可以得到 –
不清楚你在問什麼......總結伯爵? 'var sum = result [「a」]。Sum(x => x.SSum.Count);'? – stefankmitph