Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于一个关键字,我向两个不同的站点发送请求。但我只能访问其中一个响应';s根对象_C#_Json_Unity3d - Fatal编程技术网

C# 基于一个关键字,我向两个不同的站点发送请求。但我只能访问其中一个响应';s根对象

C# 基于一个关键字,我向两个不同的站点发送请求。但我只能访问其中一个响应';s根对象,c#,json,unity3d,C#,Json,Unity3d,我正在做一个关键字搜索,在两个不同的网站上寻找一个部分。我有他们的api,我得到了响应。这两个响应在RootObject中有不同的JSON和不同的变量。 这会导致错误 namespace OctopartApi { using Newtonsoft.Json; using RestSharp; using System; using System.Collections; using System.Collections.Generic; usi

我正在做一个关键字搜索,在两个不同的网站上寻找一个部分。我有他们的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";
    }


}
namespace-OctopartApi
{
使用Newtonsoft.Json;
使用RestSharp;
使用制度;
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine;
Net系统;
使用UnityEngine.UI;
公共类关键字搜索1:单一行为
{
公共输入字段mainputfield;
公共画布可以;
公共浮动x,y;
无效开始(){
mainInputField.onendIt.AddListener(委托{LockInput(mainInputField);});
}
无效锁定输入(输入字段输入)
{
ExecuteSearch(input.text);
}
public void ExecuteSearch(字符串输入)
{
//--您的搜索查询--
字符串查询=inp;
字符串octopartUrlBase=”http://octopart.com/api/v3";
字符串octopartUrlEndpoint=“部件/搜索”;
字符串apiKey=“57af648b”;
//创建搜索请求
var client=新的RestClient(octopartUrlBase);
var req=new RestRequest(octopartUrlEndpoint,Method.GET)
.AddParameter(“apikey”,apikey)
.AddParameter(“q”,查询)
.AddParameter(“开始”、“0”)
.AddParameter(“限制”、“10”);
//执行搜索并获得结果
var resp=客户端执行(req);
字符串octojson=resp.Content;
RootOb hh=JsonUtility.FromJson(octojson);//找不到RootOb(但可以识别根)
Manufacturer=hh.Manufacturer;//未找到
}
//--您的API密钥--(https://octopart.com/api/register)
私有常量字符串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;
}
[System.Serializable]
公共类RootOb
{
公共字符串\uuuu类\uuuuu;
公共品牌;
公共制造商;
公共字符串mpn;
公共字符串八进制url;
公开上市;
公共列表重定向的UID;
公共字符串uid;
}
如何在第二节课中访问响应

Root res = JsonUtility.FromJson<Root>(jsonString);//No issues here 
Root res=JsonUtility.FromJson(jsonString)//这里没有问题
由于某些原因,我只能访问Root而不能访问RootOb。我做错了什么? 找不到类型或命名空间名称“RootOb”。是否缺少程序集引用


编辑:我尝试删除根类,现在检测到RootOb!JsonUtility是否应该只有一个定义?

您必须输入导致错误的代码error@Programmer,你好,又是我:)。我只有一个问题。如何从rootobject访问深度嵌套的对象。根对象有一个列表类。。其中存在另一个list类,在该类中我有一个值“packaging”。RootObj{public class List res;}结果{public class item;}项{public class List offers;}提供{字符串打包;}。我想访问打包。我建议你用你的代码和你想访问的类发布新的问题。只需确保发布回答问题所需的所有信息。您必须输入导致问题的代码error@Programmer,你好,又是我:)。我只有一个问题。如何从rootobject访问深度嵌套的对象。根对象有一个列表类。。其中存在另一个list类,在该类中我有一个值“packaging”。RootObj{public class List res;}结果{public class item;}项{public class List offers;}提供{字符串打包;}。我想访问打包。我建议你用你的代码和你想访问的类发布新的问题。只需确保发布回答问题所需的所有内容。