skip to Main Content

I’m trying to deseralizse a JSON message in run time and extract the values then assign to variables.

 dynamic Json = JsonConvert.DeserializeObject(result);

This is value deserialised in Json variable which I found in debugger

{{
  "geo": [
    {
      "x": 16324865.646724658,
      "y": -4967300.1743641077
    }
  ]
}}

I’m getting error when I tried to assign the parsed message into variables.

  double x1 = 0;
  double y1 = 0;

      
  x1 = Json.geo.x.Value();
  y1 = Json.geo.y.Value();

Error Message:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''Newtonsoft.Json.Linq.JArray' does not contain a definition for 'x''

2

Answers


  1. Chosen as BEST ANSWER

    This has fixed the issue.

    double x1 = 0;
    double y1 = 0;
    
          
      x1 = Json.geo[0].x;
      y1 = Json.geo[0].y;
    

  2.   double x1 = 0;
      double y1 = 0;
    
          
      x1 = Json.geo[0].x.Value();
      y1 = Json.geo[0].y.Value();
    

    Try the above once?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search