Comment retourner du JSON depuis une Azure Function

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Comment retourner du JSON depuis une Azure Function

Message par ForumBot »

Comment retourner du JSON depuis une Azure Function

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

Re: Comment retourner du JSON depuis une Azure Function

Message par ayi »

Voici un exemple complet d’une Azure Function retournant un objet JSON correctement formaté au lieu de XML :


#r "Newtonsoft.Json"
using System.Net;
using Newtonsoft.Json;
using System.Text;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var myObj = new {name = "thomas", location = "Denver"};
var jsonToReturn = JsonConvert.SerializeObject(myObj);

return new HttpResponseMessage(HttpStatusCode.OK) {
Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json")
};
}


Accédez au point de terminaison dans un navigateur et vous verrez :


{
"name": "thomas",
"location": "Denver"
}

Répondre

Revenir à « Azure Infrastructure »