json parse
yashina
Member Posts: 16
I have a json file

I want read total_pages
Name DataType Subtype Length
JToken DotNet Newtonsoft.Json.Linq.JToken.'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
ItemList DotNet Newtonsoft.Json.Linq.JArray.'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
Item DotNet Newtonsoft.Json.Linq.JObject.'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
result := HttpResponseMessage.Content.ReadAsStringAsync.Result;
i :=0;
JToken := JToken.Parse(result);
ItemList := JToken.SelectToken('pagination');
FOREACH Item IN ItemList DO BEGIN
i :=i+1;
IF i=3 THEN BEGIN
MESSAGE(Item.GetValue('total_pages').ToString);
EVALUATE(TotalPage,Item.GetValue('total_pages').ToString);
END;
END;
But Error in Item.GetValue('total_pages').ToString

Whats wrong ?

I want read total_pages
Name DataType Subtype Length
JToken DotNet Newtonsoft.Json.Linq.JToken.'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
ItemList DotNet Newtonsoft.Json.Linq.JArray.'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
Item DotNet Newtonsoft.Json.Linq.JObject.'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
result := HttpResponseMessage.Content.ReadAsStringAsync.Result;
i :=0;
JToken := JToken.Parse(result);
ItemList := JToken.SelectToken('pagination');
FOREACH Item IN ItemList DO BEGIN
i :=i+1;
IF i=3 THEN BEGIN
MESSAGE(Item.GetValue('total_pages').ToString);
EVALUATE(TotalPage,Item.GetValue('total_pages').ToString);
END;
END;
But Error in Item.GetValue('total_pages').ToString

Whats wrong ?
0
Answers
-
You have defined 'itemlist' to be a JArray, but in your json I don't see that it is an array - it looks like a nested object?
And why do you loop through the elements? I think the memberlist of a json object is unordered, so you should not assume that the third element is the "total_pages" element.Jan Veenendaal0 -
I understand that this is an object, not an array. How to correctly access an nested object and its value? For the first time I work with JSON.0
-
thank you! You are very helpful. I understood what's the matter.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
