I am working on creating an API that call the other third party API. The third party API is an REST API and returns response in the JSON format when I call it in the web browser
I am trying to get the same response when I call the third party API from my API.
What I have been doing is getting the response from the third party API in a string. But I am checking if there is a way I can get in the JSON format so I can return them directly. The return type of the get method is
IHttpActionResult
. If I am returning as string the response looks likeAny help is greatly appreciated.
user4912134user4912134
Now, if for some crazy reason we decided to remove the JSON serializer from our ASP.NET Web API serializer collection, but still had the XML serializer, we would automatically get an XML response, like the one below. Note that we would also get the same response if we had defined application/xml first in our Accept request header above. May 31, 2017 - This section lists some examples of public HTTP APIs that publish data in JSON format. These are great to get a sense of the complex.
2 Answers
Create a model to hold rest api data
Deserialize it from api
And then return that
Full example
NkosiNkosi
you can use Newtonsoft.Json ,Just add it from nuget and add this config to webapiconfig:
then use
Mostafa EsmaeiliMostafa Esmaeili
Not the answer you're looking for? Browse other questions tagged c#asp.netjsonapiasp.net-web-api or ask your own question.
![From From](http://www.gregreda.com/images/scraping-api-response.png)
How to receive JSON object in POST using web api
Aug 14, 2017 05:17 AM|AL MUBARAK|LINK
![Json Json](/uploads/1/2/3/8/123865979/512894591.png)
Dear All,
I need to receive below JSON objects from mob app/postman client to process the request on WEB API. Could anyone please help me, how to retrieve this in my application.
I had created below classes for getting root values.
{
'Token':'********',
'TripID':'********',
'MembersFundsList':[
{
'MembersID':'83',
'MembersName':'xxxx',
'SourceId':'85',
'SourceName':'xxxxxx',
'Amount':'0.00'
},
{
'MembersID':'83',
'MembersName':'yyyy',
'SourceId':'85',
'SourceName':'yyyyyyy',
'Amount':'0.00'
},
'Token':'********',
'TripID':'********',
'MembersFundsList':[
{
'MembersID':'83',
'MembersName':'xxxx',
'SourceId':'85',
'SourceName':'xxxxxx',
'Amount':'0.00'
},
{
'MembersID':'83',
'MembersName':'yyyy',
'SourceId':'85',
'SourceName':'yyyyyyy',
'Amount':'0.00'
},
{
'MembersID':'83',
'MembersName':'zzzz',
'SourceId':'85',
'SourceName':'zzzzzz',
'Amount':'0.00'
}
]
}
'MembersID':'83',
'MembersName':'zzzz',
'SourceId':'85',
'SourceName':'zzzzzz',
'Amount':'0.00'
}
]
}
Below is my code, to retreive the JSON result from Postman client. response came to endpoint. but, can't searlize it properly. Please help me on this.. its very URGENT.
public JObject FundAllocation(JObject jsonResult)
{
dynamic json = new JObject();
{
dynamic json = new JObject();
lock (this)
{
try
{
string jsonString = JsonConvert.SerializeObject(jsonResult);
var res = JArray.Parse(jsonString);
List<FundAlloc.TripObject> items = JsonConvert.DeserializeObject<List<FundAlloc.TripObject>>(jsonString);
}
catch (Exception ex)
{
}
}
return json;
}
{
try
{
string jsonString = JsonConvert.SerializeObject(jsonResult);
var res = JArray.Parse(jsonString);
List<FundAlloc.TripObject> items = JsonConvert.DeserializeObject<List<FundAlloc.TripObject>>(jsonString);
}
catch (Exception ex)
{
}
}
return json;
}