Skip to content
Loading
  • Jignesh Kumar
    +3
    Hi rohan,
     
    Please use this one,
     
    1. var someType = JsonConvert.DeserializeObject(jsonData.ToString());  
    +3
  • +2
    This is my data after parsing here add extra breates so how to remove this .
     
     
    This--{{
    "publisResult": [
    {
    "key": {
    "SeaTerm": "flower"
    },
    "data": [
    {
    "PubliImgUrl": "https://picsum.photos/200/300.jpg",
    "Name": "Jhon",
    "Title": "gardenflowershop",
    "Description": "OnlineFlowerShopsindeliveryHongKong"
    },
    {
    "PubliImgUrl": "https://picsum.photos/200/300.jpg",
    "Name": "JhonCena",
    "Title": "weddings",
    "Description": "COM"
    }
    ]
    },
    {
    "key": {
    "SeaTerm": "Pia"
    },
    "data": [
    {
    "PubliImgUrl": "https://picsum.photos/200/300.jpg",
    "Name": "Harry",
    "Title": "benny-drinnon.com",
    "Description": "Todd"
    },
    {
    "PubliImgUrl": "https://picsum.photos/200/300.jpg",
    "Name": "Roma",
    "Title": "blogspot",
    "Description": "MichelleMorganTalksThelma"
    }
    ]
    }
    ]
    }  }-- this 
     
    +2
  • +2
    Uttam it's not working this
     
    var finalResult = JObject.Parse(data);
    string trimResult = finalResult.TrimStart('{').TrimEnd('}');
     
    +2
  • +2
    This erorr
     
    Error CS1061 'JObject' does not contain a definition for 'TrimStart' and no accessible extension method 'TrimStart' accepting a first argument of type 'JObject' could be found (are you missing a using directive or an assembly reference?)  
    +2
  • Uttam Kumar
    +2

    string trimResult = jsonData.Trim().Substring(0,1).TrimEnd('}');

    If TrimStart is not working then you can use Substring in place of that.

    +2
  • +2

    Jignesh I have already use this it's again convert json to string format.

    var someType = JsonConvert.DeserializeObject(jsonData.ToString());

    +2
  • Jignesh Kumar
    +2
    Is it Working? If no Please add your json response
    +2
  • Muhammad Imran Ansari
    +2
    @Rohan,
    Use the following code to remove first and last curly bracket from your json.Suppose yourJson is the veriable which has json string.
    1. string finalJson = yourJson.Substring(1, yourJson2.Length - 2);  
    Your finalJson veriable has value without first and last bracket. 
    +2
  • Sachin Singh
    +2
    use this
    1. var s= JsonConvert.SerializeObject(yourJson);

    2. if (s.Length > 2) {  
    3.   if(s.StartsWith("{{")) {  
    4.     s = s.Substring(2, s.Length-2);  
    5.   }  
    6.   if(s.EndsWith("}}")) {  
    7.     s = s.Substring(0, s.Length-2);  
    8.   }  
    9. }  
     
    +2