Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

This is 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;
}

I received the dictionary in Javascript as:

 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;

    }

How do I parse the keys and values to an array?

share|improve this question
    
Use parseJSON(). It's already part of jQuery. – Diodeus Dec 14 '12 at 19:46
up vote 0 down vote accepted

Something like this

function llamada_Webservice(peticion) {
var categories = peticion;
    for(item in categories{ // Data is saved in the variable named d if it's ASP.NET WebService
        var categoria = item; // The name
        var list = categories[item]; // The array that you could loop thru

    }

}
share|improve this answer
    
i give the wrong in the second line<i>var categories = peticion.d;</i> Microsoft JScript runtime error: 'd[...].key' is null or not an object – Lucas Valle Dec 14 '12 at 20:52
    
Try to remove the .d If you select the network tab in Chrome and inspect the response you could se the JSON structure. Paste it in your quesiton – Simon Edström Dec 14 '12 at 20:56
    
the image is imageshack.us/photo/my-images/32/imagensl.jpg – Lucas Valle Dec 14 '12 at 21:31
    
Now you should look at the response in the network tab. Like this: i.stack.imgur.com/1QmML.jpg – Simon Edström Dec 15 '12 at 8:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.