c# – Accessing a list/array in a JSON URL

Question:

I'm sending an array of strings via JSON, how can I access this array via url? example of some of the tests:

http://localhost:51746/api/Language/GetLanguageList?key=[loaded,error] http://localhost:51746/api/Language/GetLanguageList?key= {loaded,error}

But it didn't work, does anyone know how I can do this?

[HttpGet]
public HttpResponseMessage GetLanguageList(List<string> keys)
{
    try
    {
        #region meu codigo

        Dictionary<string, string> key_value = new Dictionary<string, string>();


        foreach (string key in keys)
        {
            key_value.Add(key,Resources.Language.ResourceManager.GetString(key));
        }

        #endregion

        return Request.CreateResponse(HttpStatusCode.OK, new ResponseApi()
        {
            Status = Status.OK,
            Message = "Sucesso",
            Response = key_value
        },
        "application/json");
    }
    catch (Exception ex)
    {
        return Request.CreateResponse(HttpStatusCode.OK, new ResponseApi()
        {
            Status = Status.NOK,
            Message = ex.Message,
            Response = null
        },
        "application/json");
    }
}

Answer:

Just repeat the name of the list variable that appears in your Controller, in your case keys , when the controller receives the request it will know it is a list and will convert automatically.

http://localhost:51746/api/Language/GetLanguageList?keys=carregando&keys=erro

If you want to send JSON will have to use the POST method, you don't send an entire object (in your case the JSON) via GET .

Scroll to Top
AllEscort