1

I don't know if it possible, but I try...:

I pass from javascript to c# any object. For exapmle:

{
    name:'ser',
    age:8
}

At server-side, I have custom class look like:

public class generaly
{
    public string FieldName { get; set; }
    public string FieldValue { get; set; }
    public bool? isKey { get; set; }
}

I need to convert my object, so after convert I want to have List of generaly objects:

    [
       {FieldName:"name", FieldValue:"ser", isKey:null},
       {FieldName:"age", FieldValue:"8", isKey:null}
    ];

I tried using dynamic type, expando object, dictionary... but it didn't help me becouse I need the finall result to be list of my class (generaly).

I there any solution to this situation?

user5260143
  • 936
  • 2
  • 9
  • 29
  • [Naming conventions](http://stackoverflow.com/questions/1618316/naming-convention-in-c-sharp) are useful: it increases readability and also helps to prevent bugs. It's also easier for others to understand your code. – Tim Schmelter Feb 18 '15 at 08:24
  • This wont be possible unless you write your own implementation to convert the javascript object into a c# object – Nilesh Feb 18 '15 at 08:28
  • Please refer : http://stackoverflow.com/questions/13496951/convert-javascript-object-into-c-sharp-object is this what you are looking for? also refer , if you can build this kind of DLL for your project http://json2csharp.com/ – Deshmukh Feb 18 '15 at 08:29
  • Here's another: http://stackoverflow.com/questions/20907775/how-to-map-json-response-to-custom-class-object – Tim Schmelter Feb 18 '15 at 08:30
  • Tim Schmelter - Can you be specific? I cannot understand how this link help me. Desmukh and Tim - the related question are not good for me. – user5260143 Feb 18 '15 at 08:36
  • What Tim and Deshmukh are saying is that you need to change your class or change the json object so that you can deserialize the object into c#. Try something like `string test = "{name:'ser', age:'9'}"; JObject obj = (JObject)JsonConvert.DeserializeObject(test); List cls = new List(); foreach (var o in obj) { cls.Add(new MyClass() { FieldName=o.Key, FieldValue = o.Value.ToString() }); }` – Nilesh Feb 18 '15 at 08:42
  • Thanks, this way I know, but I thougth may be there is sorter way... Thank you all for your answers – user5260143 Feb 18 '15 at 08:45

0 Answers0