我正在使用API通过端点/ contacts / v1 / contact / batch /来通信批量联系人
我收到一条错误消息,响应为@
{“状态”:“错误”,“消息”:“第1行第1列上的无效输入JSON:无法从VALUE_STRING令牌中反序列化java.util.ArrayList实例”,“ correlationId”:“ 3c1488a8- 24f5-4e1c-b506-18edcd870065“,” requestId“:” a85c3ea88b60a7d0e3cfe5736c819b11“}
我发送的JSON有效。我已经检查并再次检查。 请帮助:(
我的输出低于
[
{
"email": "twst@email.com",
"properties": [
{
"property": "company",
"value": "Test"
},
{
"property": "website",
"value": "www.test.com"
},
{
"property": "firstname",
"value": "Carl"
},
{
"property": "lastname",
"value": "Swann"
},
{
"property": "jobtitle",
"value": "Dr"
},
{
"property": "phone",
"value": "0789654321"
},
{
"property": "product",
"value": "Khaos Control Hybrid"
},
{
"property": "eventList_2019",
"value": "Spring Fair"
}
]
},
{
"email": "email@yes .com",
"properties": [
{
"property": "company",
"value": "Another one"
},
{
"property": "website",
"value": "www.a.ither.com"
},
{
"property": "firstname",
"value": "Anither"
},
{
"property": "lastname",
"value": "One"
},
{
"property": "jobtitle",
"value": "Com"
},
{
"property": "phone",
"value": "0789675341"
},
{
"property": "product",
"value": "Khaos Control Hybrid"
},
{
"property": "eventList_2019",
"value": "Spring Fair"
}
]
},
{
"email": "keeley@sophieallport.com",
"properties": [
{
"property": "company",
"value": "Sophie Allport"
},
{
"property": "website",
"value": "www.sophieallport.com"
},
{
"property": "firstname",
"value": "Keeley"
},
{
"property": "lastname",
"value": "Walters"
},
{
"property": "jobtitle",
"value": "Accounts "
},
{
"property": "phone",
"value": "01778235648"
},
{
"property": "product",
"value": "Khaos Control Hybrid"
},
{
"property": "eventList_2019",
"value": "Spring Fair"
}
]
}
]
答案 0 :(得分:0)
我找到了我使用的源代码,我会尽力为你解释我的实现。
我创建的应用程序是一个移动应用程序,公司使用它来获取有关新潜在客户的信息并将该信息发送到他们的 HubSpot 帐户。
主应用程序包含一个 Prospect 类,它定义了我们想要获取的关于潜在客户的信息
public class Prospect
{
public string CompanyName { get; set; }
public string Website { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string JobTitle { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Products { get; set; }
public string Notes { get; set; }
public string ContactOwner { get; set; }
public string ShowName { get; set; }
}
与您提出的问题相关的应用程序组件包含 2 个类:
public class HubSpotProspect
{
public string email { get; set; }
public List<Property> properties { get; set; }
}
public class Property
{
public string property { get; set; }
public string value { get; set; }
}
以下代码获取所有潜在客户的列表,然后遍历它们以分配正确的属性值,然后转换为新的 HubSpotProspect 列表。然后我们将此列表序列化为 json 并将其传递给与 HubSpot API 通信的函数。
List<Prospect> _pList = _prospectList.GetProspectList(ShowName);
List _hsProspectList = new List();
foreach (Prospect p in _pList)
{
HubSpotProspect _hsp = new HubSpotProspect();
_hsp.email = p.Email;
_hsp.properties = new List<Property>();
_hsp.properties.Add(new Property { property = "company", value = p.CompanyName });
_hsp.properties.Add(new Property { property = "website", value = p.Website });
_hsp.properties.Add(new Property { property = "firstname", value = p.FirstName });
_hsp.properties.Add(new Property { property = "lastname", value = p.LastName });
_hsp.properties.Add(new Property { property = "jobtitle", value = p.JobTitle });
_hsp.properties.Add(new Property { property = "phone", value = p.Phone });
_hsp.properties.Add(new Property { property = "product", value = p.Products });
_hsp.properties.Add(new Property { property = "event_list_2019", value = p.ShowName });
_hsp.properties.Add(new Property { property = "hubspot_owner_id", value = _userProfile.GetContactOwner() });
_hsProspectList.Add(_hsp);
}
string json = JsonConvert.SerializeObject(_hsProspectList);
await SendContact(json);
与HubSpot API通信的函数如下:
private Task SendContact(string JsonString)
{
return Task.Factory.StartNew(() =>
{
string hapiKey = _userProfile.GetHapiKey();
var client = new RestClient(https://api.hubapi.com/);
var request = new RestRequest("contacts/v1/contact/batch/", Method.POST);
request.AddQueryParameter("hapikey", hapiKey);
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(JsonString);
IRestResponse response = client.Execute<HubSpotProspect>(request);
var content = response.Content;
//Console.WriteLine("RESPONSE " + content);
});
}