Мне нужно сделать несколько HTTP-запросов к этому URL, и я использую JArray.Parse для десериализации.Первые 2 раза я вызываю мой метод HTTP, он работает нормально и анализирует нормально, и я могу получить свои данные, но в третий раз, когда я вызываю метод, он выдает мне исключение.
Я предоставилкод, который я использовал.Кто-нибудь может сказать мне, что происходит?
public static string GETActionInfo(int action_input)
{
string getDevicesURL = "someURL";
string action_id = "", device_id = "",strname="";
int value=0;
JArray parsedArray=null;
HttpsClientResponse response=null;
try
{
response = crestronGetHttp(getDevicesURL); //Makes the HTTP call
if (response.Code != 200)
{
CrestronConsole.PrintLine(response.Code);
return response.Code.ToString();
}
}
catch(Exception e)
{
CrestronConsole.PrintLine("crestronGetHttp()-->"+e.Message);
}
string jsonData="";
using (Stream stream = response.ContentStream)
{
using (StreamReader reader = new StreamReader(stream))
{
try
{
jsonData = reader.ReadToEnd();
}
catch (Exception e)
{
CrestronConsole.PrintLine("ReadToEnd Exception" + e.Message + "_" + e.StackTrace);
}
string receivedData = jsonData;
try
{
parsedArray = JArray.Parse(receivedData);
}
catch (Exception e)
{
CrestronConsole.PrintLine("JArray Parsing
Exception" + e.Message + " " + e.StackTrace);
}
CrestronConsole.PrintLine("Parsed Array" + parsedArray);
try
{
foreach (JObject ob in parsedArray.Children<JObject>())
{
var name = (string)ob["name"];
if (name == "My ecobee")
{
device_id = (string)ob["_id"];
var json = (JArray)ob["actions"];
}
}
}
catch (Exception e)
{
CrestronConsole.PrintLine(" For block--->" + e.Message + "-----" + e.StackTrace);
}
}
}
}
Самое смешное, что когда я добавляю оператор печати для печати содержимого разобранного массива и вызываю этот метод, он работает просто отлично.Но когда я закомментирую оператор печати, он завершается неудачно при третьем вызове.Я подумал, может быть, это как-то связано с задержкой (поскольку для печати всего содержимого проанализированного массива требуется некоторое время).Я попытался добавить оператор сна, чтобы проверить его, но он не работает.
Исключение, которое он мне выдает:
JArray Parsing Exception-->Unterminated string. Expected
delimiter: ". Line 1, position 34779.______ at
Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)
at Newtonsoft.Json.JsonTextReader.ParseProperty(Char firstChar)
at Newtonsoft.Json.JsonTextReader.ParseObject(Char currentChar)
at Newtonsoft.Json.JsonTextReader.ReadInternal()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r)
at Newtonsoft.Json.Linq.JArray.Load(JsonReader reader)
at Newtonsoft.Json.Linq.JArray.Parse(String json)
at yonomi_one_test_one.ControlSystem.GETActionInfo(Int32 action_input)
at yonomi_one_test_one.ControlSystem.ecoDec(String args)
at Crestron.SimplSharpProInternal.SimplSharpProManager.f()
For block--->NullReferenceException----- at yonomi_one_test_one.ControlSystem.GETActionInfo(Int32 action_input)
at yonomi_one_test_one.ControlSystem.ecoDec(String args)