c# - Need Help getting a specific value from a JSON key/value pair -
i pulling data 3rd party api , have myself code looks this...
public partial class form1 : form { int playsystem = 2; string playid = ""; public form1() { initializecomponent(); } private void xbox_checkedchanged(object sender, eventargs e) { playsystem = 1; } public void playstation_checkedchanged(object sender, eventargs e) { playsystem = 2; } private async void searchbutton_click(object sender, eventargs e) { statdisplay.clear(); var username = namebox.text; using (var client = new httpclient()) { client.defaultrequestheaders.add("x-api-key", "xxxxxxxxxxxxxxxx"); var response = await client.getasync("https://bungie.net/platform/destiny/searchdestinyplayer/" + playsystem + "/" + username); var content = await response.content.readasstringasync(); dynamic item = newtonsoft.json.jsonconvert.deserializeobject(content); statdisplay.appendtext(item.tostring()); } } }
instead of displaying information in object string, take specific value object, store variable, , use variable in httprequest.
the output getting looks this...
{ "response": [ { "iconpath": "/img/theme/destiny/icons/icon_psn.png", "membershiptype": 2, "membershipid": "01234567890", "displayname": "xxxxxxxxxx" } ], "errorcode": 1, "throttleseconds": 0, "errorstatus": "success", "message": "ok", "messagedata": {} }
i focus on membershipid key/value.
var membershipid = (string)item.response[0].membershipid;
Comments
Post a Comment