2

I want to send a raw nested JSON using RestSharp. I am able to send a normal JSON using RestSharp as follows.

request.AddBody(new { 
            sender = "Alice", 
            receiver = "Bob", 
            message = "We did it!"});

But what I really want to achieve is :

request.AddBody(new { 
                bizcardData = "{
                    "name" = "johannes",
                    "company" = "AppLab",
                    "designation" = "Mobile App Developer",
                    "phone" = "5135921240",
                    "email" = "[email protected]",
                }", 
                transData = {
                    "date" = "20150805_221024",
                    "location" = "39.1395996,-84.5295417",
                    "tag" = "sender"
                } 
            });

But this code is not working.

I am using Firebase and there is a problem in using POST with AddParameter(); So, I want to send using raw JSO format. I am unable to send a nested JSON this way. It would be great if you could help me with suggestions as of how to do it.

Thanks!

2
  • please define "not working" - does it crash? Throw an exception? Give you a compiler error? Commented Aug 29, 2015 at 3:48
  • The compiler gives an error marking almost every single line in the code I pasted above Commented Aug 29, 2015 at 4:48

1 Answer 1

2

Well, you're malforming the content mixing strings unterminated instead of nested classes, it will not compile, change it to be real classes:

request.AddBody(new { 
            bizcardData = new {
                name = "johannes",
                company = "AppLab",
                designation = "Mobile App Developer",
                phone = "5135921240",
                email = "[email protected]",
            }, 
            transData = new {
                date = "20150805_221024",
                location = "39.1395996,-84.5295417",
                tag = "sender"
            } 
        });

This will translate to a JSON object like this:

{
    bizCardData: { "name": "johannes", "company": /* and so on */ },
    transData: { "date": "20..:" /* and so on */ }
}
Sign up to request clarification or add additional context in comments.

Comments

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.