0

I have a JSON file (this is a small piece of it)

{
  "colors": {
    "1": {
      "name": "Dye Remover", 
      "base_rgb": [], 
      "cloth": {}, 
      "leather": {}, 
      "metal": {
        "brightness": 5, 
        "contrast": 1.05469, 
        "hue": 38, 
        "saturation": 0.101563, 
        "lightness": 1.36719, 
        "rgb": [
          96, 
          91, 
          83
        ]
      }

This isn't the end of the JSON... there is more - i just wanted to cut it off here. Also leather, cloth, and base_rgb all are correct they are not empty, they are just collapsed and I copy/pasted it that way. [TL;DR the JSON is 100% fine.]


I am wondering how to get the rgb value inside "metal" and use it to set the background color of a div.

I already have code that gets the array and selects different ones and prints their metal-rgb value. I need to know how to USE the array as rgb values.

user3387566
  • 157
  • 1
  • 1
  • 8

1 Answers1

2

I already have code that gets the array and selects different ones and prints their metal-rgb value. I need to know how to USE the array as rgb values.

In that case, let's say you assign the 3 values to the variables a, b and c:

document.body.style.backgroundColor= 'rgb(' + a + ',' + b + ',' + c + ')';

The above code sets the background color of the body with the values of a, b and c. I hope I understood your problem correctly

Raul Rene
  • 10,014
  • 9
  • 53
  • 75
  • I thought I would have to use that sort of joining method. I will use it I was just wondering if there was a different way. – user3387566 Apr 04 '14 at 11:00