MAK
MAK

Reputation: 1288

Json string value doesn't give all data

Here's my json string

{
  "tracking_information": {
    "status_name": "Picked", 
    "status_code": "PCK", 
    "status_date": "2017-11-12T07:28:01.123272", 
    "source": "Web", 
    "status_date_local": "2017-11-12 11:28:01", 
    "status_description": "Picked up"
  }, 
  "order_information": {
    "tracking_no": "34120022", 
    "so_number": "44", 
    "client_ref": "Test Order"
  }
}

this is my code

byte[] json_orders = wc.DownloadData(url);

var bytesAsString = Encoding.ASCII.GetString(json_orders);

dynamic jsonObj = JsonConvert.DeserializeObject(bytesAsString);
foreach (var obj in jsonObj.tracking_information)
{
    string track_info = obj.Value;
}

The obj variable holds only status name value. how can I get the status code and associated information.

Upvotes: 0

Views: 61

Answers (2)

AJ -
AJ -

Reputation: 631

Your data is already there your problem with the way your retrieve it, you can always your quick watch to examine all object information.

enter image description here

Upvotes: 0

Emre Kabaoglu
Emre Kabaoglu

Reputation: 13146

There is no required for loop. Just try like that;

var statusCode = jsonObj.tracking_information.status_code
var statusName= jsonObj.tracking_information.status_name

Upvotes: 1

Related Questions