How To Get Color Id And HexString From JSON?

Sorry for the length

I want to get color id and HexString from JSON Text

My JSON Text:

[{
“colorId”: 0,
“hexString”: “#000000”,
“rgb”: {
“r”: 0,
“g”: 0,
“b”: 0
},
“hsl”: {
“h”: 0,
“s”: 0,
“l”: 0
},
“name”: “Black”
}, {
“colorId”: 1,
“hexString”: “#800000”,
“rgb”: {
“r”: 128,
“g”: 0,
“b”: 0
},
“hsl”: {
“h”: 0,
“s”: 100,
“l”: 25
},
“name”: “Maroon”
}, {
“colorId”: 2,
“hexString”: “#008000”,
“rgb”: {
“r”: 0,
“g”: 128,
“b”: 0
},
“hsl”: {
“h”: 120,
“s”: 100,
“l”: 25
},
“name”: “Green”
}, {
“colorId”: 3,
“hexString”: “#808000”,
“rgb”: {
“r”: 128,
“g”: 128,
“b”: 0
},
“hsl”: {
“h”: 60,
“s”: 100,
“l”: 25
},
“name”: “Olive”
}, {
“colorId”: 4,
“hexString”: “#000080”,
“rgb”: {
“r”: 0,
“g”: 0,
“b”: 128
},
“hsl”: {
“h”: 240,
“s”: 100,
“l”: 25
},
“name”: “Navy”
}, {
“colorId”: 5,
“hexString”: “#800080”,
“rgb”: {
“r”: 128,
“g”: 0,
“b”: 128
},
“hsl”: {
“h”: 300,
“s”: 100,
“l”: 25
},
“name”: “Purple”
}, {
“colorId”: 6,
“hexString”: “#008080”,
“rgb”: {
“r”: 0,
“g”: 128,
“b”: 128
},
“hsl”: {
“h”: 180,
“s”: 100,
“l”: 25
},
“name”: “Teal”
}, {
“colorId”: 7,
“hexString”: “#c0c0c0”,
“rgb”: {
“r”: 192,
“g”: 192,
“b”: 192
},
“hsl”: {
“h”: 0,
“s”: 0,
“l”: 75
},
“name”: “Silver”
}, {
“colorId”: 8,
“hexString”: “#808080”,
“rgb”: {
“r”: 128,
“g”: 128,
“b”: 128
},
“hsl”: {
“h”: 0,
“s”: 0,
“l”: 50
},
“name”: “Grey”
}, {
“colorId”: 9,
“hexString”: “#ff0000”,
“rgb”: {
“r”: 255,
“g”: 0,
“b”: 0
},
“hsl”: {
“h”: 0,
“s”: 100,
“l”: 50
},
“name”: “Red”
}

Search in community first. Search results for 'get item from json' - Kodular Community

I have tried all the method.

http://ai2.appinventor.mit.edu/reference/other/json-web-apis.html

Can you show your blocks??

First of all your json , provided above misses a ] at the end . Assuming this is the case you have an array with 10 objects inside. One way to get color id and HexString is

2 Likes

Actually, that JSON contains plenty of codes so I deleted the remaining if not it will look like a big tail. Anyway thank you, let me try and let you know @dora_paz

2 Likes

IMG-20210208-WA0008 IMG-20210208-WA0007

This error I am getting @dora_paz

Can you provide api or full json to check it ?

that is too big!!!

1 Like

Yes, that’s why I have added limited JSON but Dora kodular asked full list , that’s why. Don’t mistake me friends…

1 Like

Try this and tell me if it works.

colors_json.aia (16.2 KB)

2 Likes

Thank you @dora_paz … nice effort.

I got such reply in my app.

it works but how to get the colors seperated from the json list

1 Like

You have two lists one with all hex colors and one with all colors_id . I didn’t want to add values in labels , I just wanted to see if data received ok either from web or from text. Now modify the code . What are you truing to do with this colors ?

1 Like

Ok, thanks a lot @dora_paz , Thanks for your effort…

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.