I have wrote a basic web service using .net which I intend to use in a mobile app. It currently outputs Json however the structure it not quite what I need.
The models I've created
[DataContract]
class PoiList
{
[DataMember]
public List<Poi> Pois { get; set; }
}
[DataContract]
class Poi
{
[DataMember]
public string title { get; set; }
[DataMember]
public string latitude { get; set; }
[DataMember]
public string longitude { get; set; }
}
Then i added some test data:
PoiList poiList = new PoiList
{
Pois = new List<Poi>()
};
Poi p = new Poi
{
title = "whatever",
latitude = "-2.45554",
longitude = "52.5454645"
};
poiList.Pois.Add(p);
p = new Poi
{
title = "weeee",
latitude = "-2.45554",
longitude = "52.5454645"
};
poiList.Pois.Add(p);
string ans = JsonConvert.SerializeObject(poiList, Formatting.Indented);
This is what the returned string looks like:
{ "Pois": [ { "title": "shit", "latitude": "-2.45554", "longitude": "52.5454645" }, { "title": "weeee", "latitude": "-2.45554", "longitude": "52.5454645" } ] }
...and this is what I want the outputted Json to look like:
string TempString = @"{ ""pois"":
[{ ""poi"":
{
""title"": ""Test title"",
""latitude"": ""-2.4857856"",
""longitude"": ""54.585656""
}},
{ ""poi"":
{
""title"": ""Halfords"",
""latitude"": ""-2.575656"",
""longitude"": ""53.5867856""
}}]}";
Basically the only difference being the "poi" next to each object in the list. Is there a simple way to include this? I should add I am using the newtonsoft.json package.