我正在進行人臉識別項目,並且正在使用Microsoft Azure認知服務。不太清楚爲什麼我無法糾正自己的Json Malformed Synax,我以爲我在6個月前就認識了這個。我想創建一個組名稱,所以我打電話給'Person Group API',每次我跟隨MS示例我在我的代碼中收到錯誤,但是在API測試控制檯中沒有問題,這裏是我從MS站點借用的代碼示例:Microsoft Face API 1.0錯誤資源未找到
{「error」:{「code」:「ResourceNotFound」,「message」:「找不到請求的資源。」 }}
並在控制檯模式下運行的代碼:我想在這裏,但我又覺得它的json格式不正確,我只是不知道我又做錯了這次
static async void CreateGroup()
{
string key1 = "YourKey";
// azure the one should work
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add
("Ocp-Apim-Subscription-Key", key1);
var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/
persongroups/{personGroupId}?" + queryString;
HttpResponseMessage response;
// Request body
string groupname = "myfriends";
string body = "{\"name\":\"" + groupname + ","+ "\"}";
// Request body
using (var content = new StringContent
(body, Encoding.UTF8, "application/json"))
{
await client.PostAsync(uri, content)
.ContinueWith(async responseTask =>
{
var responseBody = await responseTask.Result
.Content.ReadAsStringAsync();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Response: {0}", responseBody);
Console.WriteLine("");
Console.WriteLine("Group Created.... ");
Console.WriteLine("Hit ENTER to exit...");
Console.ReadKey();
});
response = await client.PutAsync(uri, content);
Console.WriteLine("what is this {0}", response.ToString());
Console.ReadKey();
}// end of using statement
}// end of CreateGroup
#endregion
根據該網站,我需要發送給ms的字段名稱是'name'; 「用戶數據」,這是可選
任何支持最歡迎在這裏
感謝