Note that there are some explanatory texts on larger screens.

plurals
  1. PODecoding Json data from API
    text
    copied!<p>I am new to Json and have to deserialize some Json data received from a url. I am using an API provided for me to log a user into an application.</p> <h2>The API:</h2> <p>Logging in</p> <p>To login, make the following call</p> <pre><code>&lt;site&gt;/Users/login/username:&lt;email&gt;/password:&lt;password&gt;.json </code></pre> <p>• Success Response</p> <pre><code>{ “response”:{ “sessionId” : “&lt;sessionId&gt;”, “businesses” : [{ “&lt;bizId-1&gt;” : “&lt;bizName-1&gt;”, “&lt;bizId-2&gt;” : “&lt;bizName-2&gt;” , “&lt;bizId-n&gt;” : “&lt;bizName-n&gt;” }] }, “messages” :{"msgs":"","errs":""} } </code></pre> <p>An example of an actual response is as below.</p> <pre><code>{ "response":{ "sessionId":"50b702d8-78dc-4d65-9de8-2510c327a7be", "businesses":[ {"50c657af0ad8-4ce7-bb08-1d60c327a7be":"All of The Lights"}, {"50cf705a-ded4-4c7d-95df-51c8c327a7be":"Tomatoes Inc"}, {"50d2cf88-e664-4103-99f9-1aa0c327a7be":"Joe's Jalepinos"}, {"50d2d9b9-c358-4129-b9ec-1aa0c327a7be":"Pizza Place"}, {"50eed93e-f49c-4dff-8c7a-33f0c327a7be":"Samsung"}, {"51036f10-e9c0-47ecb73d-0f50c327a7be":"Peppers"}, {"51036fcd-a6b8-4103-8e160f82c327a7be":"Puppy"} ] }, "messages":{"msgs":"","errs":""} } </code></pre> <p>I have the following code:</p> <pre><code>try { serverUrl = "https://eko-app.com/Users/login/username:" + usernameEntered + "/password:" + passwordEntered + ".json"; var w = new WebClient(); var jsonData = string.Empty; // make the login api call jsonData = w.DownloadString(serverUrl); if (!string.IsNullOrEmpty(jsonData)) { var dataResult = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); // need help here } } catch (Exception ex) { MessageBox.Show(ex.Message); } </code></pre> <p>I first want to retrieve the session Id from the response. If it exists, then a user is allowed to login, if the session id is null then login is rejected. How do I do this?</p> <p>Also, once a user is logged in, I would like to create a list showing the number of businesses per user and their respective business Ids.</p> <p>Any help appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload