Send a Dictionary<String,List<String>> over to a JavaScript array

Welcome to my web service!

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Dictionary<string,List<string>> GetCategorias()
{
    var diccionario = new Dictionary<string, List<string>>();
    var categoria = "Recursos Humanos";
    diccionario.Add(categoria,new List<string>());
    diccionario[categoria].Add("Busqueda de recursos");
    diccionario[categoria].Add("Busqueda de recursos humanos");

    var categoria1 = "Informatica";
    diccionario.Add(categoria1, new List<string>());
    diccionario[categoria1].Add("IT");
    diccionario[categoria1].Add("Departamento de Insfractructura");

    //var serializer = new JavaScriptSerializer();
    //string json = serializer.Serialize((object)diccionario);

    return diccionario;
}

After receiving the dictionary in Javascript:

 function get_Categorias_Comunidades() {
        $.ajax({
            type: "POST",
            url: "Lista_Categoria_comunidad.asmx/GetCategorias",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: llamada_Webservice,
            error: llamada_Error
        });
    }
    function llamada_Webservice(peticion) {
        debugger;

    }

Any suggestions on how I can parse the keys and values into an array?

Answer №1

Here is an example:

function call_WebService(request) {
var items = request;
    for(entry in items{ // Information is stored in the variable named d when using ASP.NET WebService
        var category = entry; // The label
        var itemList = items[entry]; // The list that can be iterated through

    }

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

My jQuery form is not functioning properly upon initialization

Let's take a look at this sample 'template' code: $(document).on("<EVENT>", "form", function() { $(this).find(".input input").each(function() { var required = $(this).attr("required"); var checkField = $(this).clos ...

Is React-Apollo encountering a 404 network error?

I am currently exploring React-apollo and attempting to implement Server-side rendering with apollo, but I keep encountering a 404 error. Despite confirming that my graphQL endpoint is functional. Here is the specific error message: { Error: Network erro ...

Can you explain the distinction between 'rxjs/operators' and 'rxjs/internal/operators'?

When working on an Angular project, I often need to import functionalities like the Observable or switchMap operator. In such cases, there are two options available: import { switchMap } from 'rxjs/operators'; or import { switchMap } from ' ...

Regular intervals and asynchronous JavaScript and XML (AJAX) requests are

There is a simple chat tool in place to ensure the chat room stays updated: setInterval (loadLog, 2500); function loadLog(){ //Scroll height prior to the request var oldScrollHeight = document.getElementById("chatMessages").scrollHeight - 20; ...

Encountering an illegal invocation error in jQuery

Recently delving into the world of jQuery, I am attempting to call a C# function from JavaScript using AJAX and jQuery. Additionally, I need to pass some parameters while making the call to the C# function. Here is how I am attempting to achieve this: var ...

Utilizing Three.js in your HTML code

Currently, I am using c9.io as my IDE to write and test code for a website. Despite my efforts to import the code outside of c9.io, it is still not functioning properly. (I am confident that the issue is not with the three.js script itself.) My HTML code c ...

What is the best way to save the data from a char* pointer?

The code provided below demonstrates how to convert an int/char value to binary: char* int2bin(int value, char* buffer, int bufferSize) { char *nextChar = buffer + bufferSize-1; // location to write the least significant bit *nextChar ...

Building a Modal in React and Triggering it for Display, followed by Making an AJAX Request upon Submission

Check out my CodePen snippet (minus delete ajax request): http://codepen.io/martincarlin87/pen/KzPWOw I've been diving into the world of React recently, and I'm working on converting a page in my web application to utilize React instead of just ...

Show the HTML element once the v-for loop has been completed

I am facing an issue with displaying elements using a v-for loop in my object. Here is the code snippet: <template v-for="(item, index) in myObject"> <v-row :key="index"> <v-col> <v-t ...

The functionality to show the login status is currently malfunctioning

I have a login status indicator section on my homepage which is connected to an ajax-php database. The login button performs two actions when clicked. <input value="Login" type="button" onclick='logInUser(/*function to handle login request*/);upda ...

Creating an 8-bit grayscale JPEG image using HTML5 and encoding it from a canvas source

Is there a simple method to convert an 8-bit grayscale JPEG from Canvas using client side technologies in a web browser (such as HTML5, canvas, WebGL, and JavaScript)? Are there any pre-made JavaScript libraries available for use, without requiring extens ...

JavaScript regular expressions only recognize certain characters

When submitting a form, I need to validate a field and ensure that only specific characters are allowed. The permitted characters include: a-z A-Z 0-9 % . " ' & - @ # $ * / + = [ ] ! I attempted to use the following regex for validation: var r ...

The search filter containing both the objectClass=user and displayName attributes is not valid

Error:Internal : Could not execute code stage because an exception was thrown by the code stage: The search filter (&(objectClass=user)(|(displayName)) is invalid. emailAddress = ""; displayName = "Smith"; DirectorySearcher oSearch = new DirectorySea ...

Encountering errors during the installation of packages using npm

Can someone please assist me with fixing these errors? I am a beginner in the world of web development and encountered this issue while working with react.js and setting up lite-server. Any guidance on how to resolve it would be greatly appreciated. ...

Issue with custom function not being triggered by datepicker onSelect in Internet Explorer with JQuery

I have a datepicker set up like this: $("#startDate").datepicker({ onSelect: changeDate }); This is used with the following input field: <input type="text" id="startDate" value="" class="dateField"/> This setup works well in Chrome, but encou ...

Exploring JSON arrays with HiveSQL

In my Hive table, I am working with data generated from reading a Sequence File in the HDFS. These sequence files are formatted as JSON and resemble the following: {"Activity":"Started","CustomerName":"CustomerName3","DeviceID":"StationRoboter","OrderID ...

How do I fix the build error that says "Operator '+' cannot be used with types 'number[]'?

The function below is designed to generate unique uuidv4 strings. function uuidv4() { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => ( c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)) ...

Using 3 dots argument in Angular 5 to assign values to an array

I stumbled upon this line of code in Angular. Can someone explain its meaning? this.columns = [...this.columns, col]; My guess is that this relates to the immutable concept of arrays. ...

When using the jQuery datepicker on dynamically generated input fields, the selected date automatically updates the first input field

I am currently integrating date inputs with attached datepicker functionality. The issue I am facing is that when I select a date in the first input and proceed to pick another date in the second or subsequent inputs, the last selected date appears in the ...

Using jQuery AJAX for uploading multiple files, each file is sent to the server one at a time using the AJAX method

Here is the HTML code snippet that I am currently working with: <form id="submit-form"> <input type="file" id="resume" name="resume[]" class="inputFileHidden" multiple> <input type="submit"> </form> My goal ...