का उपयोग कर जेएसओएन को अज्ञात ऑब्जेक्ट पर deserialize JSON.NET का उपयोग कर किसी ऑब्जेक्ट को deserlaize करते हैं, लेकिन मैं इसे उपयोग करने वाली ऑब्जेक्ट की वर्तमान संरचना के साथ काम करने के लिए नहीं मिल सकता।JSON.NET
http://dorobantu.me/post/2010/08/22/Deserializing-JSON-to-anonymous-types-in-C.aspx
मेरे वस्तु वर्तमान में liks लग रहा है इस
[
{
"ID": "Concurrent User",
"FieldType": 190,
"value": ""
},
{
"ID": "System Type",
"FieldType": 191,
"value": null
}
]
इम त्रुटि मिल रही है (मैं वस्तुओं की एक सूची पास करना चाहते हैं):
Cannot deserialize JSON array into type '<>f__AnonymousType1`3[System.String,System.String,System.String]'.
क्या मैं जरूरत है कुछ इसी तरह है उदाहरण के लिए # 2, एक कंटेनर ऑब्जेक्ट जिसमें एक सूची है। किसी भी मदद की सराहना की है। धन्यवाद
सी # कोड:
public void GetPoints()
{
string inputFields = HttpContext.Current.Request["inputFields"];
// var test = new { ID = string.Empty, FieldType = string.Empty, Description = string.Empty };
var example = new { containerArray = new { ID = string.Empty, FieldType = string.Empty, Description = string.Empty } };
var fields = JsonConvert.DeserializeAnonymousType(inputFields, example);
}
जावास्क्रिप्ट:
$('.quoteonly :input').live('change keyup', function() {
var $container = $('#quoteonly-container');
var containerObject = {};
var containerArray = [];
$container.find('.quoteonly :input').each(function() {
var fieldType = $(this).data('fieldtype');
var id = $(this).data('id');
var currentObject = { 'ID': id, 'FieldType': fieldType };
switch (fieldType) {
case 190: //textbox
currentObject.value = $(this).val();
break;
case 191: //select
currentObject.value = $(this).val();
break;
case 192: //radio
currentObject.value = $(this).prop('checked') == true ? 1 : 0;
break;
case 193: //checkbox
currentObject.value = $(this).prop('checked') == true ? 1 : 0;
break;
}
containerArray.push(currentObject);
containerObject.containerArray = containerArray;
});
$.ajax({
url: '../SentinelOperationsUI/GenericHandler.ashx',
data: { 'FunctionName': 'GetPoints', 'inputFields': JSON.stringify(containerObject) },
success: function (data) {
}
});
});
आप एक contxt प्राप्त करने के लिए कुछ और कोड जोड़ सकते हैं? कॉलिंग कोड और उसके बाद परिणाम – Mharlin
@Mharlin का उपयोग – Johan