Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:44:44+00:00 2026-05-30T19:44:44+00:00

I have wrote a basic web service using .net which I intend to use

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:44:46+00:00Added an answer on May 30, 2026 at 7:44 pm

    No need to declare many tiny classes just to output a json string. You can create an anonymous object to serialize like below:

    var obj = new { pois = new List<object>() };
    obj.pois.Add(new { poi = new {title = "Test title", latitude = "-2.4857856", longitude = "54.585656" } });
    obj.pois.Add(new { poi = new {title = "Halfords"  , latitude = "-2.4857856", longitude = "53.5867856" } });
    
    string json = JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented);
    
    Console.WriteLine(json);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal: Provide a web service using Visual Basic or C# or .NET that interacts
I have a .Net 4 project that has to consume a SOAP Web Service.
I have to integrate an existing, simple asp.net web forms app including postbacks etc.
I'm new to Clojure and have been using Compojure to write a basic web
I Have wrote a question which got a right answer here about emysql encoding.
I have wrote the code below which was taken from Java How to program
Hello every one I have wrote a simple code in html5 in which I
Here is code I use to POST into RESTful web service. My problem is
I have only the most basic knowledge of web scripting, but i'm trying to
I currently have a TCP server application written in .Net that receives and submits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.