eBay SDK 使用 c# 获取 JSON 中的项目
eBay SDK get item in JSON using c#
需要 JSON 中的项目,使用来自 ebay sdk 的 c#
这里是 python 做同样事情的代码
import pyodbc
import requests, json, re
server=r"DRIVER={SQL Server Native Client 11.0};Trusted_Connection=yes; SERVER=WIN-
JA0M2L5D05K\ECOM;DATABASE=ebay; UID=sa; PASSWORD=1"
conn = pyodbc.connect(server)
params = (
('callname', 'GetSingleItem'),
('responseencoding', 'JSON'),
('appid', 'abc'),
('siteid', '77'),
('version', '967'),
('ItemID', '111859090492'),
('IncludeSelector', 'Variations,ItemSpecifics,Details,Description,VariationSpecifics'),
)
response = requests.get('http://open.api.ebay.com/shopping';, params=params, verify=False)
x = json.dumps(json.JSONDecoder().decode(response.text))
conn = pyodbc.connect(server)
ccc = conn.cursor()
x=ccc.execute(""" INSERT INTO [ebay].[dbo].[ee] (json) VALUES (?) """,x)
conn.commit()
print(x)
我已经这样做了,但是它抛出异常
static void Main(string[] args)
{
// create a new service
Shopping svc = new Shopping();
// set the URL and it's parameters
// Note: appid will go here,
svc.Url = "http://open.api.ebay.com/shopping?appid=YOUR-ID&version=969&siteid=0&callname=GetSingleItem&responseencoding=JSON";
// create a new request type
GetSingleItemRequestType request = new GetSingleItemRequestType();
request.ItemID = "111859090492";
request.IncludeSelector = "Variations,ItemSpecifics,Details,Description,VariationSpecifics";
// create a new response type
GetSingleItemResponseType response = new GetSingleItemResponseType();
try
{
// make the call
response = svc.GetSingleItem(request);
}
catch (Exception ex)
{
// catch generic exception
Console.WriteLine(ex.Message);
Console.ReadKey();
return;
}
Console.WriteLine(response);
Console.ReadKey();
}
catch 块给出了我需要的结果,但它在实际结果之前有这个错误
客户端发现 'text/plain;charset=utf-8' 的响应内容类型,但预期为 'text/xml'。
请求失败并显示错误消息:
这对我来说很完美
private void send(string item)
{
string html = "";
string url = "http://open.api.ebay.com/shopping?appid=YOUR-APP-ID&version=969&siteid=77&callname=GetSingleItem&responseencoding=JSON&IncludeSelector=Variations,ItemSpecifics,Description,Details,VariationSpecifics&ItemID="+item;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse responce = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = responce.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
}
}
}
textBox1.Text=html;
html = "";
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
send(txtid.Text);
}
需要 JSON 中的项目,使用来自 ebay sdk 的 c#
这里是 python 做同样事情的代码
import pyodbc
import requests, json, re
server=r"DRIVER={SQL Server Native Client 11.0};Trusted_Connection=yes; SERVER=WIN-
JA0M2L5D05K\ECOM;DATABASE=ebay; UID=sa; PASSWORD=1"
conn = pyodbc.connect(server)
params = (
('callname', 'GetSingleItem'),
('responseencoding', 'JSON'),
('appid', 'abc'),
('siteid', '77'),
('version', '967'),
('ItemID', '111859090492'),
('IncludeSelector', 'Variations,ItemSpecifics,Details,Description,VariationSpecifics'),
)
response = requests.get('http://open.api.ebay.com/shopping';, params=params, verify=False)
x = json.dumps(json.JSONDecoder().decode(response.text))
conn = pyodbc.connect(server)
ccc = conn.cursor()
x=ccc.execute(""" INSERT INTO [ebay].[dbo].[ee] (json) VALUES (?) """,x)
conn.commit()
print(x)
我已经这样做了,但是它抛出异常
static void Main(string[] args)
{
// create a new service
Shopping svc = new Shopping();
// set the URL and it's parameters
// Note: appid will go here,
svc.Url = "http://open.api.ebay.com/shopping?appid=YOUR-ID&version=969&siteid=0&callname=GetSingleItem&responseencoding=JSON";
// create a new request type
GetSingleItemRequestType request = new GetSingleItemRequestType();
request.ItemID = "111859090492";
request.IncludeSelector = "Variations,ItemSpecifics,Details,Description,VariationSpecifics";
// create a new response type
GetSingleItemResponseType response = new GetSingleItemResponseType();
try
{
// make the call
response = svc.GetSingleItem(request);
}
catch (Exception ex)
{
// catch generic exception
Console.WriteLine(ex.Message);
Console.ReadKey();
return;
}
Console.WriteLine(response);
Console.ReadKey();
}
catch 块给出了我需要的结果,但它在实际结果之前有这个错误
客户端发现 'text/plain;charset=utf-8' 的响应内容类型,但预期为 'text/xml'。 请求失败并显示错误消息:
这对我来说很完美
private void send(string item)
{
string html = "";
string url = "http://open.api.ebay.com/shopping?appid=YOUR-APP-ID&version=969&siteid=77&callname=GetSingleItem&responseencoding=JSON&IncludeSelector=Variations,ItemSpecifics,Description,Details,VariationSpecifics&ItemID="+item;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse responce = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = responce.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
}
}
}
textBox1.Text=html;
html = "";
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
send(txtid.Text);
}