How can I convert my variable Result to an object using JSONConvert?












6















I'm using .NET Core for Linux for a Console Program.
Using Http functionality I'm get some information coming from a Webservice.
Then I'm trying to cast the result to an object but I'm not able to use JSON.



I read this article but I don't find any example and I don't have access to JavaScriptSerializer



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a deserialized of my variable result using JSON (JObject obj = (JObject)JsonConvert.DeserializeObject(result);) But I don't find any JSON object
}
}


EDIT
I would like to know how can I use JSON to convert my variable result to an object like I do usually with c#:



        JObject obj = (JObject)JsonConvert.DeserializeObject(result);


I hope you will be able to help me.



Many thanks,










share|improve this question

























  • What exactly is the question?

    – Chris Pickford
    Jun 29 '17 at 8:46











  • Sorry I missed it. My question is: How can I convert my variable Result to an object using JSONConvert

    – eldondano
    Jun 29 '17 at 8:49













  • Are you using visual studio? which version of it? project.json or csproj based .NET Core project?

    – Martin Ullrich
    Jun 29 '17 at 9:49
















6















I'm using .NET Core for Linux for a Console Program.
Using Http functionality I'm get some information coming from a Webservice.
Then I'm trying to cast the result to an object but I'm not able to use JSON.



I read this article but I don't find any example and I don't have access to JavaScriptSerializer



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a deserialized of my variable result using JSON (JObject obj = (JObject)JsonConvert.DeserializeObject(result);) But I don't find any JSON object
}
}


EDIT
I would like to know how can I use JSON to convert my variable result to an object like I do usually with c#:



        JObject obj = (JObject)JsonConvert.DeserializeObject(result);


I hope you will be able to help me.



Many thanks,










share|improve this question

























  • What exactly is the question?

    – Chris Pickford
    Jun 29 '17 at 8:46











  • Sorry I missed it. My question is: How can I convert my variable Result to an object using JSONConvert

    – eldondano
    Jun 29 '17 at 8:49













  • Are you using visual studio? which version of it? project.json or csproj based .NET Core project?

    – Martin Ullrich
    Jun 29 '17 at 9:49














6












6








6


2






I'm using .NET Core for Linux for a Console Program.
Using Http functionality I'm get some information coming from a Webservice.
Then I'm trying to cast the result to an object but I'm not able to use JSON.



I read this article but I don't find any example and I don't have access to JavaScriptSerializer



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a deserialized of my variable result using JSON (JObject obj = (JObject)JsonConvert.DeserializeObject(result);) But I don't find any JSON object
}
}


EDIT
I would like to know how can I use JSON to convert my variable result to an object like I do usually with c#:



        JObject obj = (JObject)JsonConvert.DeserializeObject(result);


I hope you will be able to help me.



Many thanks,










share|improve this question
















I'm using .NET Core for Linux for a Console Program.
Using Http functionality I'm get some information coming from a Webservice.
Then I'm trying to cast the result to an object but I'm not able to use JSON.



I read this article but I don't find any example and I don't have access to JavaScriptSerializer



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a deserialized of my variable result using JSON (JObject obj = (JObject)JsonConvert.DeserializeObject(result);) But I don't find any JSON object
}
}


EDIT
I would like to know how can I use JSON to convert my variable result to an object like I do usually with c#:



        JObject obj = (JObject)JsonConvert.DeserializeObject(result);


I hope you will be able to help me.



Many thanks,







c# json console .net-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 24 '18 at 3:43









HEWhoDoesn'tKnow

286113




286113










asked Jun 29 '17 at 8:40









eldondanoeldondano

72228




72228













  • What exactly is the question?

    – Chris Pickford
    Jun 29 '17 at 8:46











  • Sorry I missed it. My question is: How can I convert my variable Result to an object using JSONConvert

    – eldondano
    Jun 29 '17 at 8:49













  • Are you using visual studio? which version of it? project.json or csproj based .NET Core project?

    – Martin Ullrich
    Jun 29 '17 at 9:49



















  • What exactly is the question?

    – Chris Pickford
    Jun 29 '17 at 8:46











  • Sorry I missed it. My question is: How can I convert my variable Result to an object using JSONConvert

    – eldondano
    Jun 29 '17 at 8:49













  • Are you using visual studio? which version of it? project.json or csproj based .NET Core project?

    – Martin Ullrich
    Jun 29 '17 at 9:49

















What exactly is the question?

– Chris Pickford
Jun 29 '17 at 8:46





What exactly is the question?

– Chris Pickford
Jun 29 '17 at 8:46













Sorry I missed it. My question is: How can I convert my variable Result to an object using JSONConvert

– eldondano
Jun 29 '17 at 8:49







Sorry I missed it. My question is: How can I convert my variable Result to an object using JSONConvert

– eldondano
Jun 29 '17 at 8:49















Are you using visual studio? which version of it? project.json or csproj based .NET Core project?

– Martin Ullrich
Jun 29 '17 at 9:49





Are you using visual studio? which version of it? project.json or csproj based .NET Core project?

– Martin Ullrich
Jun 29 '17 at 9:49












1 Answer
1






active

oldest

votes


















0














You'll simply need some kind of dependency which is available for .NET core which can help you deserialize json.



Newtonsoft.Json is defacto standard and is available in .NET core in order to use it you have to add it into your project.json file



"dependencies" {
...
"Newtonsoft.Json": "10.0.3"
},


The appropriate using statement in your class



using Newtonsoft.Json


you can then deserialize using JsonConvert.DeserializeObject(json);



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a JSON Convert of my variable result
var yourObject = JsonConvert.DeserializeObject(result);
}
}





share|improve this answer


























  • Thanks for your answer. But when I try to add this dependencie I have following error messge: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) NETCoreTest..NETCoreApp,Version=v1.0 And The dependency Newtonsoft.Json >= 10.0.3 could not be resolved

    – eldondano
    Jun 29 '17 at 9:36













  • Did you add the dependency in project.json? The error message says there's a problem with it. If so try $ dotnet restore in console. Or simply look up how to add nugget package to .net core.

    – pijemcolu
    Jun 29 '17 at 9:40











  • How to add a nugget package: ardalis.com/how-to-add-a-nuget-package-using-dotnet-add

    – pijemcolu
    Jun 29 '17 at 9:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44820207%2fhow-can-i-convert-my-variable-result-to-an-object-using-jsonconvert%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You'll simply need some kind of dependency which is available for .NET core which can help you deserialize json.



Newtonsoft.Json is defacto standard and is available in .NET core in order to use it you have to add it into your project.json file



"dependencies" {
...
"Newtonsoft.Json": "10.0.3"
},


The appropriate using statement in your class



using Newtonsoft.Json


you can then deserialize using JsonConvert.DeserializeObject(json);



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a JSON Convert of my variable result
var yourObject = JsonConvert.DeserializeObject(result);
}
}





share|improve this answer


























  • Thanks for your answer. But when I try to add this dependencie I have following error messge: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) NETCoreTest..NETCoreApp,Version=v1.0 And The dependency Newtonsoft.Json >= 10.0.3 could not be resolved

    – eldondano
    Jun 29 '17 at 9:36













  • Did you add the dependency in project.json? The error message says there's a problem with it. If so try $ dotnet restore in console. Or simply look up how to add nugget package to .net core.

    – pijemcolu
    Jun 29 '17 at 9:40











  • How to add a nugget package: ardalis.com/how-to-add-a-nuget-package-using-dotnet-add

    – pijemcolu
    Jun 29 '17 at 9:50
















0














You'll simply need some kind of dependency which is available for .NET core which can help you deserialize json.



Newtonsoft.Json is defacto standard and is available in .NET core in order to use it you have to add it into your project.json file



"dependencies" {
...
"Newtonsoft.Json": "10.0.3"
},


The appropriate using statement in your class



using Newtonsoft.Json


you can then deserialize using JsonConvert.DeserializeObject(json);



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a JSON Convert of my variable result
var yourObject = JsonConvert.DeserializeObject(result);
}
}





share|improve this answer


























  • Thanks for your answer. But when I try to add this dependencie I have following error messge: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) NETCoreTest..NETCoreApp,Version=v1.0 And The dependency Newtonsoft.Json >= 10.0.3 could not be resolved

    – eldondano
    Jun 29 '17 at 9:36













  • Did you add the dependency in project.json? The error message says there's a problem with it. If so try $ dotnet restore in console. Or simply look up how to add nugget package to .net core.

    – pijemcolu
    Jun 29 '17 at 9:40











  • How to add a nugget package: ardalis.com/how-to-add-a-nuget-package-using-dotnet-add

    – pijemcolu
    Jun 29 '17 at 9:50














0












0








0







You'll simply need some kind of dependency which is available for .NET core which can help you deserialize json.



Newtonsoft.Json is defacto standard and is available in .NET core in order to use it you have to add it into your project.json file



"dependencies" {
...
"Newtonsoft.Json": "10.0.3"
},


The appropriate using statement in your class



using Newtonsoft.Json


you can then deserialize using JsonConvert.DeserializeObject(json);



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a JSON Convert of my variable result
var yourObject = JsonConvert.DeserializeObject(result);
}
}





share|improve this answer















You'll simply need some kind of dependency which is available for .NET core which can help you deserialize json.



Newtonsoft.Json is defacto standard and is available in .NET core in order to use it you have to add it into your project.json file



"dependencies" {
...
"Newtonsoft.Json": "10.0.3"
},


The appropriate using statement in your class



using Newtonsoft.Json


you can then deserialize using JsonConvert.DeserializeObject(json);



    public async void CallApi(Object stateInfo)
{
var client = new HttpClient();
var requestContent = new FormUrlEncodedContent(new { new KeyValuePair<string, string>("pair", "XETHZEUR"), });
HttpResponseMessage response = await client.PostAsync("https://api.kraken.com/0/public/Trades", requestContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
String result = await reader.ReadToEndAsync();
//Here I would like to do a JSON Convert of my variable result
var yourObject = JsonConvert.DeserializeObject(result);
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 29 '17 at 9:23

























answered Jun 29 '17 at 9:15









pijemcolupijemcolu

867923




867923













  • Thanks for your answer. But when I try to add this dependencie I have following error messge: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) NETCoreTest..NETCoreApp,Version=v1.0 And The dependency Newtonsoft.Json >= 10.0.3 could not be resolved

    – eldondano
    Jun 29 '17 at 9:36













  • Did you add the dependency in project.json? The error message says there's a problem with it. If so try $ dotnet restore in console. Or simply look up how to add nugget package to .net core.

    – pijemcolu
    Jun 29 '17 at 9:40











  • How to add a nugget package: ardalis.com/how-to-add-a-nuget-package-using-dotnet-add

    – pijemcolu
    Jun 29 '17 at 9:50



















  • Thanks for your answer. But when I try to add this dependencie I have following error messge: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) NETCoreTest..NETCoreApp,Version=v1.0 And The dependency Newtonsoft.Json >= 10.0.3 could not be resolved

    – eldondano
    Jun 29 '17 at 9:36













  • Did you add the dependency in project.json? The error message says there's a problem with it. If so try $ dotnet restore in console. Or simply look up how to add nugget package to .net core.

    – pijemcolu
    Jun 29 '17 at 9:40











  • How to add a nugget package: ardalis.com/how-to-add-a-nuget-package-using-dotnet-add

    – pijemcolu
    Jun 29 '17 at 9:50

















Thanks for your answer. But when I try to add this dependencie I have following error messge: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) NETCoreTest..NETCoreApp,Version=v1.0 And The dependency Newtonsoft.Json >= 10.0.3 could not be resolved

– eldondano
Jun 29 '17 at 9:36







Thanks for your answer. But when I try to add this dependencie I have following error messge: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) NETCoreTest..NETCoreApp,Version=v1.0 And The dependency Newtonsoft.Json >= 10.0.3 could not be resolved

– eldondano
Jun 29 '17 at 9:36















Did you add the dependency in project.json? The error message says there's a problem with it. If so try $ dotnet restore in console. Or simply look up how to add nugget package to .net core.

– pijemcolu
Jun 29 '17 at 9:40





Did you add the dependency in project.json? The error message says there's a problem with it. If so try $ dotnet restore in console. Or simply look up how to add nugget package to .net core.

– pijemcolu
Jun 29 '17 at 9:40













How to add a nugget package: ardalis.com/how-to-add-a-nuget-package-using-dotnet-add

– pijemcolu
Jun 29 '17 at 9:50





How to add a nugget package: ardalis.com/how-to-add-a-nuget-package-using-dotnet-add

– pijemcolu
Jun 29 '17 at 9:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44820207%2fhow-can-i-convert-my-variable-result-to-an-object-using-jsonconvert%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python