私はjsonを持っています。Newtonsoft.Json
を使用してjsonを脱灰しようとしていますが、リストに値がありません。私は通常私のseralizationコードがあるJson2charpjsonのkeyvalueペアをシリアライズできません
を使用してJSONモデルのクラスを作成し、このlocal_infoとservice_mapが
動的データです:
これは私のJSONが
{
"status": "success",
"msg": "success",
"code": 1,
"data": {
"country": "India",
"countryid": "766",
"operator": "Airtel India",
"operatorid": "1371",
"connection_status": "99",
"destination_msisdn": "919895070723",
"destination_currency": "INR",
"product_list": "100,200,300,330,350,440,500,1000",
"service_fee_list": "0.00,0.00",
"retail_price_list": "7.50,14.50,21.50,70.50",
"wholesale_price_list": "6.05,12.03,29.97,59.85",
"local_info_value_list": "100.00,1000.00",
"local_info_amount_list": "87.00,175.00,887.00",
"local_info_currency": "INR",
"authentication_key": "16809",
"error_code": "0",
"error_txt": "Transaction successful",
"nick_name": "eldho",
"price_map": {
"100": "7.50",
"200": "14.50",
"300": "21.50",
"330": "23.50",
"350": "25.00",
"440": "31.50",
"500": "35.50",
"1000": "70.50"
},
"local_info": {
"100": "87.00",
"200": "175.00",
"300": "264.00",
"330": "290.40",
"350": "350.00",
"440": "387.20",
"500": "442.00",
"1000": "887.00"
},
"service_map": {
"100": "0.00",
"200": "0.00",
"300": "0.00",
"330": "0.00",
"350": "0.00",
"440": "0.00",
"500": "0.00",
"1000": "0.00"
},
"operator_logo": "https:\/\/fm.transfer-to.com\/logo_operator\/logo-1371",
"promo_code": 0,
"benef_id": "16598"
}
}
アップデートどのように見えるかですこのように
using (var _client = new HttpClient())
{
_client.BaseAddress = new Uri(baseServiceUri);
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>("someparameter",token),
new KeyValuePair<string,string>("id",myId.ToString()),
});
var response = await _client.PostAsync(new Uri(baseAccessPoint, UriKind.Relative), content);
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException(response.ReasonPhrase);
}
//I get value in this
var responseResult = await response.Content.ReadAsStringAsync();
//Unable to deseralize it.
return JsonConvert.DeserializeObject<BeneficoryMobileDTO>(responseResult, new JsonSerializerSettings()
{
//NullValueHandling = NullValueHandling.Ignore,
Error = JsonDeserializeErrorHandler,
});
}
私のモデルはこのように見えます。
[DataContract]
public class BeneficoryMobileDTO
{
[DataMember]
public string status { get; set; }
[DataMember]
public string msg { get; set; }
[DataMember]
public string code { get; set; }
[DataMember(Name = "data")]
public BeneficoryMobileDetailsDTO BeneficoryMobileDetails { get; set; }
}
public class BeneficoryMobileDetailsDTO
{
//I have removed some property to show things that doesn't work
//THIS CAN'T BE SERALIZED
[DataMember(Name = "PriceMap")]
public dynamic price_map { get; set; }
//THIS CAN'T BE SERALIZED
[DataMember(Name = "ServiceMap")]
public dynamic service_map { get; set; }
//THIS CAN'T BE SERALIZED
[DataMember(Name = "LocalInfo")]
public object LocalInfo { get; set; }
[DataMember]
public int benef_id { get; set; }
}
のみ
LocalInfo
、ServiceMap
とPriceMap
このプロパティはnull値を得ています。それ以外はすべてシリアル化されています。
PLSのは、私はプロパティの名前である私はあなたの問題のために間違った
:Visual Studioを残したくない場合は、あなたのために必要なクラスを自動生成するクラスとしてクールな機能ペーストJSONがあります数字は常に同じですか(つまり、100,200,300,330など)? – DavidG
これらは動的です – Eldho