我正在进行关键字搜索,以查找两个不同网站中的某个部分。我有他们的api,我确实得到了响应。两个响应在RootObject中有不同的JSON和不同的变量。 这会导致错误
namespace OctopartApi
{
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using System.Net;
using UnityEngine.UI;
public class KeywordSearch1 : MonoBehaviour
{
public InputField mainInputField;
public Canvas can;
public float x, y;
void Start () {
mainInputField.onEndEdit.AddListener(delegate {LockInput(mainInputField); });
}
void LockInput(InputField input)
{
ExecuteSearch (input.text);
}
public void ExecuteSearch(string inp)
{
// -- your search query --
string query = inp;
string octopartUrlBase = "http://octopart.com/api/v3";
string octopartUrlEndpoint = "parts/search";
string apiKey = "57af648b";
// Create the search request
var client = new RestClient(octopartUrlBase);
var req = new RestRequest(octopartUrlEndpoint, Method.GET)
.AddParameter("apikey", apiKey)
.AddParameter("q", query)
.AddParameter("start", "0")
.AddParameter("limit", "10");
// Perform the search and obtain results
var resp = client.Execute(req);
string octojson = resp.Content;
RootOb hh = JsonUtility.FromJson<RootOb> (octojson);// RootOb NOT FOUND ( but Root is recognized)
Manufacturer manufacturer = hh.manufacturer;//NOT FOUND
}
// -- your API key -- (https://octopart.com/api/register)
private const string APIKEY = "57af648b";
}
}
这是我的模特课
[System.Serializable]
public class RootOb
{
public string __class__;
public Brand brand;
public Manufacturer manufacturer;
public string mpn;
public string octopart_url;
public List<Offer> offers;
public List<string> redirected_uids;
public string uid;
}
我如何在第二课中访问响应
Root res = JsonUtility.FromJson<Root>(jsonString);//No issues here
出于某种原因,我只能访问Root而不能访问RootOb。我做错了什么? 类型或命名空间名称`RootOb&#39;无法找到。你错过了装配参考吗?
编辑:我尝试删除Root类,现在检测到RootOb!应该只有一个JsonUtility def吗?