我實現我的應用程序的一種方法,當它從Visual Studio OK運行良好,但是當它從任務調度得到執行這個錯誤日誌文件中解析值時遇到意外的字符:c。路徑',線0,位置0
系統。異常:在提取供應商列表時,同步過程中發生異常,方法名稱爲GetSuppliers。異常是Newtonsoft.Json.JsonReaderException:解析值時遇到意外字符:C.行0,位置0.在Newtonsoft.JsonTextReader.ParseValue()位於Newtonsoft.JsonTextReader.ReadInternal()位於Newtonsoft.Json.JsonTextReader .Read()在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader讀卡器,JsonContract合同,布爾hasConverter,布爾inArray)在Newtonsoft.Json.Serialization
我的方法
public string GetSuppliers()
{
SqlConnection connect = null; var spdb = new Syncdbsource();
try
{
var hsp = new hspservice.MyServiceSoapClient("MyServiceSoap");
var sdetails = hsp.GetSupplier();
List<SupplierDetails> supplierslist = null; var countSuppliers = 0;
if (!string.IsNullOrEmpty(sdetails))
{ supplierslist = JsonConvert.DeserializeObject<List<SupplierDetails>>(sdetails); }
return countSuppliers + "Inserted";
}
catch (SocketException)
{
System.Threading.Thread.Sleep(25000);
try
{
var output = GetSuppliers();
return output;
}
catch (Exception ex)
{
var exception = new Exception(@"Exception occurred in the Sync Process while fetching the suppliers list and method name is GetSuppliers.
The Exception is " + Environment.NewLine + ex.Message);
var message = exception.Message;
SendMail.InsertIssue(message.Replace("'", "''"));
return "-1";
}
}
catch (Exception excp)
{
var exception = new Exception(@"Exception occurred in the Sync Process while fetching the suppliers list and method name is GetSuppliers.
The Exception is " + Environment.NewLine + excp);
SendMail.InsertIssue(exception.ToString().Replace("'", "''"));
}
finally
{
if (connect != null && connect.State == ConnectionState.Open)
{ connect.Dispose(); }
}
return string.Empty;
}
的Json返回字符串
[{「SUPPLIERID」:「10148」,「SUPPLIERNAME」:「ALLIED ELECTR ONICS - LUD「,」TNAMC「:」ACCOUNTS RECEIVABLE「,」TNAMB「:」「,TNAME」:「FORT WORTH」,「TPSTC」:「76113-2325」,「TCSTE」:「TX」 「:」USA「,」PHONE「:」616-365-9960「,」FAX「:」6163659895「},{」SUPPLIERID「:」10159「,」SUPPLIERNAME「:」ALRO STEEL CO。「,」TNAMC「 :「PO BOX 30382「,」TNAMB「:」「,」TNAME「:」LANSING「,」TPSTC「:」48909-7882「,」TCSTE「:」MI「,」TCCTY「:」USA「 616-248-7687 「 」傳真「:」 6164522779「}]
public class SupplierDetails
{
private string _supplierCode;
private string _supplierName;
private string _internalCompanyId;
private string _address1;
private string _address2;
private string _city;
private string _state;
private string _country;
private string _zipCode;
private string _fax;
private string _phone;
public string SUPPLIERID
{
get {
return !string.IsNullOrEmpty(_supplierCode) ? _supplierCode : "-";
}
set
{
_supplierCode = value.Trim();
}
}
public string SUPPLIERNAME
{
get {
return !string.IsNullOrEmpty(_supplierName) ? _supplierName : "-";
}
set
{
_supplierName = value.Trim();
}
}
public string CompanyID
{
get {
return !string.IsNullOrEmpty(_internalCompanyId) ? _internalCompanyId : "-";
}
set
{
_internalCompanyId = value.Trim();
}
}
public string TNAMC
{
get {
return !string.IsNullOrEmpty(_address1) ? _address1 : "-";
}
set
{
_address1 = value.Trim();
}
}
public string TNAMB
{
get {
return !string.IsNullOrEmpty(_address2) ? _address2 : "-";
}
set
{
_address2 = value.Trim();
}
}
public string TNAME
{
get {
return !string.IsNullOrEmpty(_city) ? _city : "-";
}
set
{
_city = value.Trim();
}
}
public string TCSTE
{
get {
return !string.IsNullOrEmpty(_state) ? _state : "-";
}
set
{
_state = value.Trim();
}
}
public string TCCTY
{
get {
return !string.IsNullOrEmpty(_country) ? _country : "-";
}
set
{
_country = value.Trim();
}
}
public string TPSTC
{
get {
return !string.IsNullOrEmpty(_zipCode) ? _zipCode : "-";
}
set
{
_zipCode = value.Trim();
}
}
public string PHONE
{
get
{
return !string.IsNullOrEmpty(_phone) ? _phone : "-";
}
set
{
_phone = value.Trim();
}
}
public string FAX
{
get
{
return !string.IsNullOrEmpty(_fax) ? _fax : "-";
}
set
{
_fax = value.Trim();
}
}
public SupplierDetails()
{
//
// TODO: Add constructor logic here
//
}
}
你可以發佈GetSuppliers的代碼嗎?或者原始的迴應是什麼? –
對不起Josh Knack,這是第三方服務方法獲取Json字符串,我們沒有代碼。 –
好的,那麼你可以請你寄一份正在退貨的樣品嗎?此外,供應商詳細信息的代碼會很有幫助。 –