我已经复习了很多关于这个问题的帖子,但仍然有问题。我正在使用Newtonsoft.Json文件以及以下代码:
string url = @"https://https://someSite.com/indexes('myIndex')search=SEARCH_PHONES:";
string phoneNumber = "5550005555";
url += phoneNumber;
HttpWebRequest request = HttpWebRequest.CreateHttp(url);
request.Method = "GET";
request.Headers.Add("api-key", "####");
WebResponse response = request.GetResponse();
Stream imageStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(imageStream, encode);
string s = readStream.ReadToEnd();
JObject joResponse = JObject.Parse(s);
JArray array = (JArray)joResponse["value"];
string customer = array[0].ToString();
{
"@odata.context": "https://someSite.com/indexes('myIndex')/$metadata#docs",
"value": [
{
"@search.score": 10.933167,
"CUSTOMER_DIM_ID": "77049309",
"SOURCE_CUSTOMER_ID": null,
"PORTSTORE_ID": "0326_1448401",
"FIRST_NM": "First Name",
"LAST_NM": "Last Name",
"ADDR_LINE_1": "133 Main St",
"ADDR_LINE_2": null,
"CITY": "MyCity",
"STATE_CD": "IL",
"POSTAL_CD": "99999",
"COUNTRY": "United States",
"EMAIL_ADDR": "myEmail@gmail.com",
"BIRTH_DT": null,
"PHONE": "5550005555",
"GENDER_CD": "F",
"SEARCH_EMAILS": [
"myEmail@gmail.com"
],
"SEARCH_PHONES": [
"5550005555"
],
"JUS_EMAIL_OPTIN": true,
"JCA_EMAIL_OPTIN": true,
"LCA_EMAIL_OPTIN": true,
"JUS_DM_OPTIN": true,
"JCA_DM_OPTIN": true,
"LCA_DM_OPTIN": true,
"MOBILE_OPTIN": false,
"LIFETIME_REVENUE": "138.1800",
"LIFETIME_UNITS": 7,
"NTH_ORDER": 2,
"FIRST_PURCHASE_DT": "2016-02-11T00:00:00Z",
"LAST_PURCHASE_DT": "2016-02-19T00:00:00Z",
"AVG_LAG": 8,
"IsDeleted": false,
"UPDATE_DT": "2016-02-19T00:00:00Z"
}
]
}
我没有权限更改响应。我尝试使用json2sharp创建对象,然后简单地反序列化,但它说@搜索.score“也是无效的”@odata.context文件". 在我注释掉C代码中的那些行之后,它没有正确地反序列化(所有内容都为空),我需要能够检索客户信息并将其分配给我的自定义类。