このJSONレスポンスをデシリアライズするとエラーが発生する理由を教えていただけますか?C#.Net JSONシリアル化が機能しない
public T PostData<T>(string command, Dictionary<string, object> postData)
{
postData.Add("command", command);
postData.Add("nonce", Helper.GetCurrentHttpPostNonce());
var jsonString = PostString(Helper.ApiUrlHttpsRelativeTrading, postData.ToHttpPostString());
var output = JsonSerializer.DeserializeObject<T>(jsonString);
return output;
}
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
internal static T DeserializeObject<T>(this JsonSerializer serializer, string value)
{
using (var stringReader = new StringReader(value)) {
using (var jsonTextReader = new JsonTextReader(stringReader)) {
/*
An exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll but was not handled in user code
Additional information: Could not create an instance of type Jojatekok.PoloniexAPI.WalletTools.IBalance. Type is an interface or abstract class and cannot be instantiated. Path '1CR.available', line 1, position 20.
ERROR's ON NEXT LINE :
*/
return (T)serializer.Deserialize(jsonTextReader, typeof(T));
}
}
}
戻ってくる文字列の値は、次のとおり { "1CR": "利用可能": "0.00000000"、 "onOrders": "0.00000000"、 "btcValue": "0.00000000"}}
Iがバランスのためのインタフェースを持っている:
public interface IBalance
{
double QuoteAvailable { get; }
double QuoteOnOrders { get; }
double BitcoinValue { get; }
}
とバランスモデル:
public class Balance : IBalance
{
[JsonProperty("available")]
public double QuoteAvailable { get; private set; }
[JsonProperty("onOrders")]
public double QuoteOnOrders { get; private set; }
[JsonProperty("btcValue")]
public double BitcoinValue { get; private set; }
}
それはdeserialではないのですが、 JSONをBalanceオブジェクトにizingする。私はこのエラーが発生しています:
このエラーは、発生するコードに記載されています。
ヒント
私はGUですあなたは 'DeserializeObject'と呼びますが、 'DeserializeObject 'でなければなりません。なぜJsonConvertを使わないのですか? –
こんにちはマキシム、JsonConvertをこのコンテキストでどのように使用できるかを示してください。 – Nickmccomb