Thursday, February 9, 2017

The ' ' character, hexadecimal value 0x20, cannot be included in a name.




Introduction

I want to convert Json file to xml file. Many code available on internet you can applied easily and It is working fine. but sometime we got an error. 

"The ' ' character, hexadecimal value 0x20, cannot be included in a name."


Solution

Sol 1- jsonStr.Replace(“ “,””);
              
With this solution, String does not contain any space.

Sol 2-
var objJson = JArray.Parse(jsonString);
 foreach (var fix in (from property in objJson.Descendants().OfType<JProperty>()
         let newName = XmlConvert.EncodeLocalName(property.Name.Replace(" """))
         where newName != property.Name
               select new { Old = property, New = new JProperty(newName, property.Value) })          .ToList())
         {
            fix.Old.Replace(fix.New);
         }

                XmlDocument xdoc = JsonConvert.DeserializeXmlNode("{\"root\":" + objJson.ToString() + "}""root");

Kashmir 370 and 35A : The Wound of india

क्या है जम्मू-कश्मीर में लागू धारा 370,35A पूर्ण विवरण Know about 370 act in Jammu एक बार फिर से राजनीति गलियारे में धारा 370,35A को ल...