I have a json data like below:
{
"ResourceStrings":
[
{
"StringKey": "TestKey",
"StringID": 1,
"Value": "This translate need to be done123fdff"
},
{
"StringKey": "SampleKey",
"StringID": 2,
"Value": "This translate need to be done345fdfd"
}
]
}
I converted this to class so below the created class:
public class ResourceString
{
public string StringKey { get; set; }
public int StringID { get; set; }
public string Value { get; set; }
}
public class RootObject
{
public List<ResourceString> ResourceStrings { get; set; }
}
Now i have some data in xliff format which i am taking from this element and updating in the Rootobject like below:
XmlDocument docXLIFF = new XmlDocument();
docXLIFF.LoadXml(xliffdata);
var jsondata = JsonConvert.DeserializeObject<RootObject> (sameJsonDataAsAbove);
List<ResourceString> rstList = jsondata.ResourceStrings.ToList();
XmlNodeList xmlNodes = docXLIFF.SelectNodes("/xliff/file/body/trans-unit");
foreach (XmlNode node in xmlNodes)
{
var getTransID = rstList.Where(t => t.StringID.ToString() == node.Attributes["id"].Value).FirstOrDefault();
if (getTransID != null)
{
var getTargetValue = node.InnerText;
getTransID.Value = getTargetValue;
}
}
So in the above code i am checking the id of xliff element with jsonList id and it's match i am getting the value of element and setting in the json list. after completing this i need the updated json list in the same json form as i mentioned above. But i am getting only the content like below:
{
"StringKey": "TestKey",
"StringID": 1,
"Value": "This translate need to be done123fdff"
}, {
"StringKey": "SampleKey",
"StringID": 2,
"Value": "This translate need to be done345fdfd"
}
How to achieve the same json structure?