I need this when my json returns. This data is retrieved from the database, but I am currently using static data.
{
"data": [
{
"id": 1,
"latitude":17.3700,
"longitude": 78.4800,
"gallery":
[
"assets/img/items/1.jpg"
]
}
]
}
I tried this in my code, but I am not getting the desired result.
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public List<> getData()
{
Account account = new Account
{
id = 1,
latitude = "17.3700",
longitude ="78.4800",
gallery = new List<string>
{
"assets/img/items/1.jpg",
"assets/img/items/2.jpg",
}
};
return new JavaScriptSerializer().Serialize(account);
}
public class Account
{
public int id { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public IList<string> gallery { get; set; }
}
Result:
{
"id":2,
"latitude":"17.3700",
"longitude":"78.4800",
"gallery":["assets/img/items/1.jpg","assets/img/items/2.jpg"]
}
source
share