我有json,試圖使用Newtonsoft.Json
將json去deseralize,但我無法獲得列表中的某些值。無法序列化json keyvaluepair
這是我的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"
}
}
更新:這local_info和service_map是動態的數據
我通常使用Json2charp
我seralization代碼爲創建一流的JSON模式像這樣
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值。所有的東西都是連續的。
請讓我知道我做錯了
數字總是相同的(即100,200,300,330等)? – DavidG
那些是動態的 – Eldho