🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / Remove white spaces in Names of dynamic JSON string field name replace

1-) C# RMOS - Remove white spaces in Names of dynamic JSON string field name replace

 

kaynak : https://www.codeproject.com/Questions/629184/Remove-white-spaces-in-Names-of-dynamic-JSON-strin

kaynak : https://stackoverflow.com/questions/53169837/deserializing-json-with-space-separated-property-names

 

   public string replaceJson()

        {

 

            string jsonString = "{nodes:[{'Node 1':'value1','Node 2':'value2'}]}";

 

            JObject jsonObject = JObject.Parse(jsonString);

            JObject newJsonObject = new JObject();

            JProperty property;

            foreach (var token in jsonObject["nodes"].Values())

            {

                property = (JProperty)token;

                newJsonObject.Add(property.Name.Replace(" ", ""), property.Value);

            }

 

            return newJsonObject.ToString();

        }

 

output :

 

{

  "Node1": "value1",

  "Node2": "value2"

}

 

 2022 Temmuz 03 Pazar
 430