-1

I'm working with HighCharts and having a little trouble getting the color variable to work so it alternates colors.

Here is my returned JSON array:

[{"y":5,"color":"colors[0]","drilldown":{"name":"June","categories":["Fictional Hospice","Virtue Hospice"],"data":[4,1],"color":"colors[3]"}}

I need to remove the double quotes just from the colors[0] and the colors[3] part in order for it to work.

How do I go about doing this?

Thanks!

user2436953
  • 45
  • 3
  • 9
  • 3
    Set your cursor behind the `"` you want to remove and hit `<- backspace` key on your keyboard. – TiMESPLiNTER Jun 19 '14 at 13:18
  • 3
    If you remove the quotes, it will no longer be valid JSON. – DaveRandom Jun 19 '14 at 13:19
  • Why do you want to remove that? You showing correct `json` format. If you need any data's from there, use [json_decode()](http://us.php.net//manual/en/function.json-decode.php) method – Ranjith Jun 19 '14 at 13:21
  • Because `"colors[0]"` is not a string. It is telling `"colors:"` which one to use. Expected format is `"colors": colors[0]` for Highcharts. – wergeld Jun 19 '14 at 13:23
  • I think @user2436953 wants to use references of the `colors` array inside his JSON but that's not possible. I would rather just use 0 and 3, and then, after decoding, use `colors[myJSON[0].color]` to get the right value out of the `color` property – Capsule Jun 19 '14 at 13:26

1 Answers1

1

If you want to use references of the colors array inside JSON, that's not possible.

I would rather just use 0 and 3 in the color property, and then, after decoding, use colors[myJSON.color] to get the right value out of the color property.

So, your JSON will look like this:

{"y":5,"color": 0,"drilldown":{"name":"June","categories":["Fictional Hospice","Virtue Hospice"],"data":[4,1],"color": 3}}

And when you want to get the right color, just use colors[jsonObject.color] instead of just jsonObject.color if you decoded your JSON string into jsonObject

Capsule
  • 6,118
  • 1
  • 20
  • 27