2

I've come across a bit of a problem. I want to convert a steam game name to its corresponding steam app id via the steamapi. I'm trying to figure out how to get the entirety of a object from a value it contains (

{"applist":{"apps":[{"appid":230410,"name":"Warframe"}, {"appid":25300,"name":"Call of Duty"}, {"appid":292410,"name":"Team Fortress 2"}]}}

for example. the name here is Warframe. but I want to grab the entirety of this object just by the "name" value. I've been looking for an answer for awhile. any help would be appreciated

I tried deserializing the response to a class. but this seemed to be useless since all objects contain the same value name just with different titles

6
  • 1
    What is "entirety"? can you show the example what you want to retrive? I can see only one object, what else are going to find? Commented Nov 9, 2022 at 19:10
  • Have a look at Array.Find(), List.Find() and Enumerable.First() for examples of how to single value in a collection based on one of its properties Commented Nov 9, 2022 at 19:10
  • 1
    @Serge i hotlinked the json value to "steamapi" its a jumble of json containing every game on the steam store containing its name and appid Commented Nov 9, 2022 at 19:12
  • @AndrewWilliamson will do! Commented Nov 9, 2022 at 19:12
  • @willcodes I'm at work, and that link is blocked by my company's firewall. It's a good idea to include the link, but it's also good to include a bit more information directly in your post in case people can't access the link. In this case, I would include the parent object/array. You don't have to include all the child items, just two or three is enough to demonstrate Commented Nov 9, 2022 at 19:16

1 Answer 1

1

you can try this code

var result=JObject.Parse(json)["applist"]["apps"].Where(a=> (string)a["name"]=="Warframe").FirstOrDefault();

//if you need id

var appid = (int) result["appid"];

//or in one line

int appid = (int) JObject.Parse(json)["applist"]["apps"]
.FirstOrDefault(a=> (string)a["name"]=="Warframe")?["appid"];
Sign up to request clarification or add additional context in comments.

5 Comments

FirstOrDefault can take the predicate directly, no need to add Where inbetween
@AndrewWilliamson I always like to separate flys from burgers.
@Serge I'm getting a System.ArgumentNullException when a game's name has a ":" in the name
@willcodes pls show the example where do you have an error
@Serge sorry for the delay! I fixed it, it was a issue with the full json response not being pulled not the code itself.

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.