Я пытаюсь создать запрос с помощью RestSharp.
У меня есть следующая строка
"{ \"name\": \"string\", \"type\": \"string\", \"parentId\": \"string\", \"Location\": [ \"string\" ]}"
Мне нужно передать это в тело json, чтобы отправить запрос POST.попробуйте следующее.
public IRestResponse PostNewLocation(string Name, string Type, Nullable<Guid> ParentId, string Locatations)
{
string NewLocation = string.Format("{ \"name\": \"{0}\", \"type\": \"{1}\", \"parentId\": \"{2}\", \"Location\": [ \"{3}\" ]}", Name, Type, ParentId, Location);
var request = new RestRequest(Method.POST);
request.Resource = string.Format("/Sample/Url");
request.AddParameter("application/json", NewLocation, ParameterType.RequestBody);
IRestResponse response = Client.Execute(request);
}
И ошибка
Message: System.FormatException : Input string was not in a correct format.
Как мне отформатировать приведенную выше строку, чтобы передать ее в тело json?
Мой тест не пройден приэта строка
string NewLocation = string.Format("{ \"name\": \"{0}\", \"type\": \"{1}\", \"parentId\": \"{2}\", \"Location\": [ \"{3}\" ]}", Name, Type, ParentId, Location);