I can use Postman or Insomnia to post the data and get result, same way i want to implement in console application,but i am unable to find way to pass my json string
Below is the json string i am passing to post using postman or insomnia
Accroding to your description,as far as I think,your json string format is wrong.
Just like this:
var json = "{ \"source\": {\"id\":\"cdl\",\"emp\":\"test\",\"0000\"}," + "\"ver\":\"2.0\"};
var record = JsonConvert.DeserializeObject(json);
Best regards,
Yijing Sun
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
58 Points
176 Posts
How do I post JSON String in console application
May 19, 2020 11:25 AM|neerajkumarmodi|LINK
Hi Support,
I can use Postman or Insomnia to post the data and get result, same way i want to implement in console application,but i am unable to find way to pass my json string
Below is the json string i am passing to post using postman or insomnia
Now I am using below code to pass it inside console application but looks it is not the correct way
Error:{StatusCode: 500, ReasonPhrase: '[json.exception.parse_error.101] parse error at line 2, column 2: syntax error while parsing object key - invalid literal; last read: '<U+0009>{<U+000D><U+000A><U+0009>â'; expected string literal'
Thanks!
All-Star
58184 Points
15655 Posts
Re: How do I post JSON String in console application
May 19, 2020 02:43 PM|bruce (sqlwork.com)|LINK
Your json is not valid. Unlike JavaScript, single quotes are not supported.
Contributor
3730 Points
1417 Posts
Re: How do I post JSON String in console application
May 20, 2020 07:21 AM|yij sun|LINK
Hi neerajkumarmodi,
Accroding to your description,as far as I think,your json string format is wrong.
Just like this:
Best regards,
Yijing Sun
All-Star
48510 Points
18072 Posts
Re: How do I post JSON String in console application
May 20, 2020 07:49 AM|PatriceSc|LINK
Hi,
Another option could be to take advantage of the PostAsJsonAsync extension method: https://docs.microsoft.com/en-us/previous-versions/aspnet/hh944339(v=vs.118)
This way you can post a .NET object (possibly declared using an anonymous type) and let a json serializer to produce the corresponding json for you.
Member
58 Points
176 Posts
Re: How do I post JSON String in console application
May 21, 2020 05:02 AM|neerajkumarmodi|LINK
It accepted double quotes like below
None
0 Points
3 Posts
Re: How do I post JSON String in console application
May 23, 2020 05:46 PM|RJ BOY|LINK
Hi,
I would suggest you first create the object then serialization in JSON format.