1

Actually I am using Json.net for serializing the object into a json string, in that i faced a suituation in which i want to serialize the object without the {} in my Json String. Is there any way to do that..

Example: Here is the class

public class Sample
{
  public String name{get;set;}
  public int id{get;set;}
}

While serializing the object of the above class, I get something like below

{"name":....,
 "id":...}

But I dont want those {} wrapping around the json string. I need as below,

"name":....,
 "id":...

So is there any way in json.net to remove them or am i need to do it using String operations?

For Example:

My two classes are as follow,

pulbic class Class1
 {
public String prop1{get;set;}
public String prop2{get;set;}
public Class2 classprop{get;set;}
  }

 public class Class2
{
public String prop3{get;set;}
public String prop4{get;set;}
 }

When I am creating the object for class Class1 as follow and serialize i am getting the json string as follow,

Class1 c1=new Class1(){prop1="hi",prop2="hey",classprop=new Class1(){prop3="bye";prop4="byyyyye"}

{ "prop1":"hi", "prop2":"hey", "classprop":{ "prop3":"bye", "prop4":"byyyyye" } }

But i need the string as follow, `{ "prop1":"hi", "prop2":"hey",
"prop3":"bye", "prop4":"byyyyye"

}`

Do you have any way solve this situation??

7
  • 3
    So you want a JSON serializer to serialize your object in a way that produces completely invalid JSON? "name": "value", "id": 5 is not valid JSON at all. Commented Nov 1, 2013 at 6:24
  • What i am going to do is append this json string into an another json string thats why i am asking or is there any way to append two json string using json.net? Commented Nov 1, 2013 at 6:26
  • 2
    why not perform that nesting pre-serialization via either anonymous types or a dictionary? Commented Nov 1, 2013 at 6:27
  • I am not good at that can you provide me a simple example?? Commented Nov 1, 2013 at 6:33
  • 2
    Have a look at this thread... stackoverflow.com/questions/12913396/… Is that what you want to do? Commented Nov 1, 2013 at 6:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.