Comment retourner du JSON depuis une Azure Function

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Comment retourner du JSON depuis une Azure Function

Message par Clippy »

Comment retourner du JSON depuis une Azure Function

ayi
Site Admin
Messages : 9242
Inscription : mer. 22 avr. 2026, 17:21

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 »