I got a JSON string value :
{"refKey":"1","recordType":"address","bureauType":"consumer","controlData":{"success":"true"},"candidateRecordScores":[{"bestScore":"7","inputRecordScores":"7"}]}
I want to change candidateRecordScores node inside inputRecordScores value as array format.
Below output format i need:
"inputRecordScores":[7]
Also candidateRecordScores child element value changed as string format to INT
Below Final output i need:
{"refKey":"1","recordType":"address","bureauType":"consumer","controlData":{"success":"true"},"candidateRecordScores":[{"bestScore":7,"inputRecordScores":[7]}]}
This is my code look like this:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;
amespace CAAS_SoftCIR
{
public class Class1
{
static void Main(string[] args)
{
string strJson = @"{
'ExpressMatch': {
'refKey': '1',
'recordType': 'address',
'bureauType': 'consumer',
'controlData': {
'success': 'true'
},
'candidateRecordScores': [
{
'bestScore': '7',
'inputRecordScores': '7'
}
]
}
}";
JObject rss = JObject.Parse(strJson);
//var rssTitle = Convert.ToString(rss["ExpressMatch"]);
var rssTitle = (object)rss["ExpressMatch"];
var json = JsonConvert.SerializeObject((object)rss["ExpressMatch"] , Formatting.None);
Console.WriteLine(jsonNew);
}
}
}
JObject(a good first step), nothing seems to relate to the task you're posting about. What has stopped you from looping through the items incandidateRecordScores, taking the value ofinputRecordScoresand then replacing the property value with an array of that value?foreach (JObject childObj in rss["ExpressMatch"]["candidateRecordScores"]) { currentValue = childObj["inputRecordScores"]; int parsedValue = int.Parse(currentValue); childObj["inputRecordScores"] = new JArray() { parsedValue }; }