Assuming I have 2 JSON Object arrays, which looks like this:
Resources:
[{
"DefinitionId": 193041,
"ResourceId": -2147290607,
"AssetId": 193041
}, {
"DefinitionId": 193042,
"ResourceId": -2147290603,
"AssetId": 193042
}]
ResourceIds
[193041, 193041, 193041, 193042]
The use-case:
I need to list the details from my Resources JSONObject for each ResourceId. For example I want to output the AssetId for every ResourceId in ResourceIds.
My plan:
I thought it would be an elegant solution to convert my Resources JSON into an associative array, so that I could access the AssetId for my ResourceId '193041' like this: Resources[193041].AssetId . The problem: I could only think about long code to convert my above Resources JSON into an associative JSON object.
The question:
How can I convert the above Resources JSON object array into an associative object array with ResourceId as key?
Desired Resources.json:
{
"-2147290607": {
"DefinitionId": 193041,
"ResourceId": -2147290607,
"AssetId": 193041
},
"-2147290603": {
"DefinitionId": 193042,
"ResourceId": -2147290603,
"AssetId": 193042
}
}