mercredi 13 février 2019

How do i reflect property over json and set value

I have a empty json, and a datasource with my datas. But this json is a dynamic object, (sample below).

        string json = "{ 'Name': '', 'Address': { 'City': '', 'State': '' }, 'Age': 0, 'Itens':[{ 'Name':'', 'Price':0 },{ 'Name':'', 'Price':0 }]}";

        //dynamic obj =  .... json ???

        foreach (PropertyInfo classProperty in obj.GetProperties())
        {
            classProperty.SetValue(obj, GetDataSourceValue(classProperty.Name), null);
        }

.... private static object GetDataSourceValue(string name) { // do anything }

How can I read this json or others, set values and navigate if has items?





Aucun commentaire:

Enregistrer un commentaire