I'm working with a json which comes from an API, here is what I'm talking about:
{
"popularity": 3.518962,
"production_companies": [
{
"name": "value1",
"id": 4
},
{
"name": "value2",
"id": 562
},
{
"name": "value13",
"id": 14654
},
{
"name": "value4",
"id": 19177
},
{
"name": "value5",
"id": 23243
}
]
}
I already can return value of popularity
As an example I need to know how can I access value of name
and which name
it is?
I also tried to convert it to an array but didn't work or I did something wrong.
Movie class :
public class Movie {
public string popularity {get; set;}
public object production_companies {get; set;}
public Movie GetBasic(string id) {
string json = @"{
"popularity": 3.518962,
"production_companies": [
{
"name": "value1",
"id": 4
},
{
"name": "value2",
"id": 562
},
{
"name": "value13",
"id": 14654
},
{
"name": "value4",
"id": 19177
},
{
"name": "value5",
"id": 23243
}
]
}";
Movie Data = JsonConvert.DeserializeObject<Movie>(json);
return Data;
}
What I've done so far:
@{
var arr = Item.production_companies.ToString().Substring(1, (Item.production_companies.ToString().Length - 2)).ToArray();
foreach(var a in arr) {
@a.name
}
}