0

im currently developing an app which has an webrequest: I got the following class (got it from json2csharp converter):

 class InventoryJsonData
    {
        public class RootObject
        {
            public bool Success { get; set; }
            public object Error { get; set; }
            public double Price { get; set; }
            public string Username { get; set; }
        }
    }

Then i did the following coding:

ValueLoadingIndicator.IsActive = true;
var httpWebRequest = (HttpWebRequest)WebRequest.Create(JsonBaseuri + IDInput.Text);
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";

There is only one RootObject in the JSON Data. How do i get now the Price value so i can convert it into string and display it. I dont know what i need to add as c# code. If you got helpful links to JSON c# tutorials and webrequest which are about this topic and can help me to move on they are appreciated as well.

2
  • you sure you want to post? Commented Jul 28, 2015 at 14:25
  • Deserialize your string to an instance of RootObject.It'll do. Commented Jul 28, 2015 at 14:27

2 Answers 2

1

Take a look and Newtonsoft Json.NET library: http://www.newtonsoft.com/json

You could also use WebClient class for you request - it's simpler to use.

Here is example code:

var url = JsonBaseuri + IDInput.Text;
var wc = new WebClient {Proxy = null};
var json = wc.DownloadString(url);
var responseModel = JsonConvert.DeserializeObject<InventoryJsonData>(json);
var price = responseModel.RootObject.Price;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, i will use the webclient ;)
0
HttpClient http = new System.Net.Http.HttpClient();
            HttpResponseMessage response = await http.GetAsync(JsonBaseuri + IDInput.Text.ToString());
            response.EnsureSuccessStatusCode();
            string content = await response.Content.ReadAsStringAsync();
            MessageDialog x = new MessageDialog(content, "JsonData");

This code gets me the Json File in windows universal apps ;) then i deserialize it -> read the answers above

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.