所以我目前正在使用 Azure 机器学习实验。我能够创建一个模型并将其作为 Web 服务发布。我还能够使用创建 Web 服务时生成的 API 文档中提供的 C# 中的示例请求/响应代码来获取响应。
我的问题是,Web 服务提供的响应包含许多信息(一长串信息),包括我的 C# 应用程序唯一需要的预测分数。唯一想到的是使用字符串操作方法来提取我想要的信息。但我认为还有比这更好的方法。我是 HTTP 请求/响应的新手,所以请详细说明答案和解释。
这是我的代码:
HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);
if (response.IsSuccessStatusCode)
{
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine("Result: {0}", result);
}
else
{
Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode));
// Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
Console.WriteLine(response.Headers.ToString());
string responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseContent);
}
这是响应消息:
{"Results":{"output1":{"type":"table","value":{"ColumnNames":["clump_thickness","size_uniformity","shape_uniformity","marginal_adhesion","epithelial_size","bare_nucleoli","bland_chromatin","normal_nucleoli","mitoses","Scored Labels","Scored Probabilities"],"ColumnTypes":["Int32","Int32","Int32","Int32","Int32","Nullable`1","Int32","Int32","Int32","Double","Double"],"Values":[["10","10","4","8","1","8","3","10","1","1","0.979712069034576"],["10","10","4","8","1","8","3","10","1","1","0.979712069034576"]]}}}}
我只想要“Values”中的值:[[...]],在这种情况下,第 9 个索引或“1”。