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 8865827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:37:03+00:00 2026-06-14T16:37:03+00:00

I’m creating a web service using ASP.NET, C#, currently it is giving XML, but

  • 0

I’m creating a web service using ASP.NET, C#, currently it is giving XML, but I’m going to get JSON, this is how I create my webmtheod:

[Webservice(Namespace="http://myurl)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfiles_1)]
[System.ComponentModel.ToolboxItem(false)]

[WebMehod]
public string myfunction()
{

string r = "......";


return r;
}

these are in an ASMX file, which I call it in my browser

  • 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-06-14T16:37:09+00:00Added an answer on June 14, 2026 at 4:37 pm

    If you want to return JSON from your method you will need to use the ScriptMethod attribute.

    Structure your method like this, notice the [ScriptMethod(ResponseFormat = ResponseFormat.Json)] attribute.

        [WebMethod()]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string MyMethod()
        {
    
        }
    

    At the moment, this method is returning a string, which can be a JSON structured string. However, you may be better to return an object, which can be parsed as JSON. List<string> as well as Class’s with standard data-types, like integers, strings etc are great for this. You can then return just that object. the ScriptMethod takes care of transforming it into JSON.

    For example:

    The Class you want to return:

          public class MyJson
          {
             public int ID;
             public List<string> SomeList;
             public string SomeText;
         }
    

    And your method to return a populated MyJson

            [WebMethod()]
            [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
            public MyJson MyMethod()
            { 
              MyJson m = new MyJson();
              m.ID = 1;
              m.SomeText = "Hello World!";
              m.SomeList = new List<string>();
              m.SomeList.Add("Foo");
              m.SomeList.Add("Bar");
    
              return m;
            }
    

    The return JSON will be structured just like the class. The property names will be used too, and your List<string> will become an array

    Call this using AJAX. JQuery in this case:

    $(document).ready(function(){
    
          $.ajax({
                type: "POST",
                url: "/YourPage.aspx/MyMethod",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
    
                 // content will be in here... I.E
                 var id = msg.d.ID;
                 var st = msg.d.SomeText;
                 var sl = msg.d.SomeList;
                 var i = sl.length;
                var firstSlItem = sl[0];
                }
            });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.