-2

I am faced with a problem, I want to obtain the value from a JSON property but the key is unknown when the request is made. I know I can stringify the JSON response and splice based on the ":" and remove the other extraneous characters, but I want to know if there is a simple way to just return the value of my JSON response object.

Here is an example:

JSON { 123456789: "DATA I NEED"}

123456789 is a unique ID that will vary based on the query string entry.

Johnny
  • 1
  • 1

2 Answers2

0

Once you've deserialized the JSON you can simply return a list of keys.

using System.Linq;

List<String> myKeys = myDict.Keys.ToList();
0

try this

var json= "{ 123456789: \"DATA I NEED\"}";

var jsonParsed=JObject.Parse(json);

var value= jsonParsed.Properties().ToArray()[0].Value.ToString(); //DATA I NEED
Serge
  • 28,094
  • 4
  • 11
  • 35