I am trying to acces an array in array in my json object. This is my code to get data:
function activate() {
$http({
method: 'GET',
url: 'Dashboard/GetDashboard'
}).then(function successCallback(response) {
var id = $scope.dashboard = response.data;
var datasource = id.Widgets[1].datasource;
console.log(datasource);
// var widgets = tryJsonConvert($scope.dashboard.Widgets);
$http({
url: 'Dashboard/GetDataSource/', params: { datasource: datasource },
method: 'GET'
}).then(function succesCallback(response) {
$scope.datasource = response.data.datasource;
});
}, function errorCallback(response) {
console.log(response);
});
}
The url: 'Dashboard/GetDashboard' gives me the following json object back:
{
"Id":1,
"UserId":2336276,
"Name":"Data",
"Widgets":[
{
"Id":0,
"description":"Test1",
"datasource":"Kri",
"charttype":"Bar",
"x":0,
"y":0,
"width":3,
"height":2
},
{
"Id":0,
"description":"Test2",
"datasource":"Kpi",
"charttype":"Heatmap",
"x":3,
"y":0,
"width":3,
"height":2
},
{
"Id":0,
"description":"Test3",
"datasource":"Loss events",
"charttype":"Pie",
"x":6,
"y":0,
"width":3,
"height":2
},
{
"Id":0,
"description":"Test4",
"datasource":"Loss events",
"charttype":"Area",
"x":9,
"y":0,
"width":3,
"height":2
}
]
}
Now I want to acces datasource from widgets with the second GET operator and get the following error:
And this is my controller method in C#:
[HttpGet]
public string GetDataSource(int id)
{
var type = (DataSourceType)id;
var o = _dashboarBusiness.GetDataSource(type = DataSourceType.KRI);
return Newtonsoft.Json.JsonConvert.SerializeObject(o);
}
I already look at this stack overflow post but it didn't work for me.
How to access an array in a JSON object?
I want to bind the var datasource on the param in the URL in the second GET operator.
What am I doing wrong?
Kind regards
UPDATE enum class:
public enum DataSourceType
{
CONTROL = 1,
RISK = 2,
MOI = 3,
LOSSEVENTS = 4,
KRI = 5
}

var type = (DataSourceType)id;because I can't castDataSourceTypeto a string.