This is a migrated thread and some comments may be shown as answers.

Json data source as array

3 Answers 185 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Ole Martin
Top achievements
Rank 1
Ole Martin asked on 21 Nov 2011, 11:36 AM

Hi,

I have come pretty far setting a chart up the way i want it, manipulating the examples provided. My problem is when Json encoding an array of the objects I use as the datasource, it does not work. I have looked around but not found any solution.

Here is my json array:

[{"0":{"counter":"10000","word":"someword1"},"1":{"counter":"9980","word":"someword21"},"2":{"counter":"9960","word":"someword3"},"3":{"counter":"9940","word":"someword4"},"4":{"counter":"9920","word":"someword5"}}]

Can anyone see a problem with the array? Or is this a wrong formatting, providing an array?

Here's the rest of the script which works without the "0","1" indexes.

Thanks for any help,

Ole M

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 21 Nov 2011, 12:57 PM
Hello Ole Martin,

 The json is valid, although strange. The structure, although featuring numeric keys, is an object, not an array. The right format should be 

[
    {"counter":"10000","word":"someword1"},
    {"counter":"9980","word":"someword21"},
    {"counter":"9960","word":"someword3"},
    {"counter":"9940","word":"someword4"},
    {"counter":"9920","word":"someword5"}
 
]

Greetings,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Petyo
Telerik team
answered on 21 Nov 2011, 12:57 PM
Hello Ole Martin,

 The json is valid, although strange. The structure, although featuring numeric keys, is an object, not an array. The right format should be 

[
    {"counter":"10000","word":"someword1"},
    {"counter":"9980","word":"someword21"},
    {"counter":"9960","word":"someword3"},
    {"counter":"9940","word":"someword4"},
    {"counter":"9920","word":"someword5"}
 
]

Greetings,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ole Martin
Top achievements
Rank 1
answered on 21 Nov 2011, 01:26 PM

Thanks for your reply Petyo, I now changed the formatting and it can be extracted.

Ole M
Tags
Charts
Asked by
Ole Martin
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Ole Martin
Top achievements
Rank 1
Share this question
or