0

I have JObject containing dynamic data for example:

{ "person":
  { "name": "myname",
     "city":"myCity",
     "dynamicUserData":{}
  }
}

now based on the city the dynamicUserData should be populated with values from Dictionary. The problem is how to add this dictionary in the dynamicUserData.

code:

var jobject=JObject.Parse(@"{ ""person"":  { ""name"": ""myname"", ""city"":""myCity"",""dynamicUserData"":{}}}");

var dic=new  Dictionary<string, string>();

foreach (var field in someFieldArray)
{
    if (field==something)
      {
        dic.Add(field,somevalue);
      }
}

//now here how can I put these values in dynamicUserData of the JObject?
1
  • Are you forced to use the exact JSON format as shown or are you free to format the JSON a bit different (and better to deserialize a dictionary)? Commented Feb 18, 2015 at 7:39

1 Answer 1

1

You should be able to achieve this without too much effort. On a JObject you can access a property the same way you would access dynamic objects. So you should be able to update the property using

jobject.person.dynamicUserData = new JObject(dic);

Or on a JObject you can access a property using jobject[key]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.