-2

I use

var obj = response.Content.ReadAsStringAsync().Result; 

to get a result like

obj = {"productId":"12345"}.

How to get the value 12345 from the response result?

Developer
  • 8,228
  • 37
  • 122
  • 230
kfneu
  • 11
  • 1

1 Answers1

-1

If you do not want to create an object & just need to quickly get the value, use Json.NET to parse your data into a JObject & then use .GetValue :

var productId = JObject.Parse(obj).GetValue("productId").Value<string>();

Or:

var productId = JObject.Parse(obj)["productId"].ToString();

Output:

"12345"

Ermiya Eskandary
  • 9,664
  • 3
  • 14
  • 25