Reputation: 229
Calling Azure search from the REST API, the results are returned in a JSON-like structure.
{"@odata.context":"https://xxxx.search.windows.net/indexes('index-blob')/$metadata#docs(metadata_storage_size,metadata_storage_last_modified,metadata_storage_name,metadata_storage_path,metadata_content_type,metadata_title)","value":[{"@search.score":0.012103397,"metadata_storage_size":1479948,"metadata_storage_last_modified":"2017-04-17T18:31:18Z","metadata_storage_name":"90e975d1-3986-4167-87d2-4d1cdbc7be09.pdf","metadata_storage_path":"xxxx","metadata_content_type":"application/pdf","metadata_title":null},{"@search.score":0.004614377,"metadata_storage_size":116973,"metadata_storage_last_modified":"2017-04-13T18:24:01Z","metadata_storage_name":"xxx.pdf","metadata_storage_path":"xxxx","metadata_content_type":"application/pdf","metadata_title":"xxx"}]}
The trouble is I can't find a way to actually deserialize that. I can't figure out a structure that would deserialize "@search.score" (or similar parameters if the query is more complex). I've tried using various JSON->C# converters (including Edit->Paste Special in VS) but nothing really works. It seems odd I'd have to manually parse these results...I'm attributing it to something I don't understand about either Azure Search or JSON.
Upvotes: 1
Views: 1528
Reputation: 8634
If you use the Azure Search .NET SDK, it will do the deserialization for you.
Upvotes: 0
Reputation: 5747
If I am understanding you correctly and the problem lies with parsing JSON objects that have special characters in their key name, then you could try using JsonProperty
attribute as such in you POCO (C# class to deserialize into):
public class AzureSearchResult {
[JsonProperty("@search.score")]
public float SearchScore { get; set;}
//other variables...
}
For more information see http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonPropertyAttribute.htm
Upvotes: 6