Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.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# 使用json数据从unity上的httpwebrequest检索图像_C#_Json_Unity3d_Httpwebrequest - Fatal编程技术网

C# 使用json数据从unity上的httpwebrequest检索图像

C# 使用json数据从unity上的httpwebrequest检索图像,c#,json,unity3d,httpwebrequest,C#,Json,Unity3d,Httpwebrequest,我正在构建一个增强现实应用程序,其中包括从互联网检索到的图像 我发现了一个类似的基本应用程序,它使用pixabay,效果非常好。你输入一个搜索词,它会返回该搜索中的所有图像,类似于谷歌图像搜索 代码如下 我不需要搜索功能,我只需要有一个按钮,有一个类别,选择后,下一个场景将显示从网站的所有图像的结果 该网站的一个例子是 任何帮助都将不胜感激。正如我提到的,pixabay代码如下 正如我所说,我不需要搜索功能,我只需要从一个特定的页面加载所有的图像 干杯 using System; using S

我正在构建一个增强现实应用程序,其中包括从互联网检索到的图像

我发现了一个类似的基本应用程序,它使用pixabay,效果非常好。你输入一个搜索词,它会返回该搜索中的所有图像,类似于谷歌图像搜索

代码如下

我不需要搜索功能,我只需要有一个按钮,有一个类别,选择后,下一个场景将显示从网站的所有图像的结果

该网站的一个例子是

任何帮助都将不胜感激。正如我提到的,pixabay代码如下

正如我所说,我不需要搜索功能,我只需要从一个特定的页面加载所有的图像

干杯

using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;


/*
 * @author Michael Hässig
 * @email michael.haessig (at) gmail (dot) com
 */
public static class PixabayApi
{
    public static string URL = "https://pixabay.com/api/";

// My API KEY - the api is public but please do not abuse 
public static string KEY = "11701417-557ad1ed3c54b52741fa32e5c";

public static PixabayImageResponse Search(string search)
{
    // create http request
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL + $"? 
 key={KEY}&q={search}");
    // set http method
    request.Method = "GET";
    // send request and auto close stream
    using (HttpWebResponse response =         
(HttpWebResponse)request.GetResponse())
    {
        // create reader for response stream
        StreamReader reader = new 
StreamReader(response.GetResponseStream());
        // read the full response into a string
        string jsonResponse = reader.ReadToEnd();
        // parse string into response model object
        PixabayImageResponse pixabayImageResponse =         
JsonUtility.FromJson<PixabayImageResponse>(jsonResponse);
        // return result
        return pixabayImageResponse;
       }
   }
使用系统;
使用系统集合;
使用System.Collections.Generic;
Net系统;
使用System.IO;
使用UnityEngine;
使用UnityEngine。联网;
/*
*@作者Michael Hässig
*@email michael.haessig(at)gmail(dot)com
*/
公共静态类PixabayApi
{
公共静态字符串URL=”https://pixabay.com/api/";
//我的API密钥-API是公开的,但请不要滥用
公共静态字符串键=“11701417-557ad1ed3c54b52741fa32e5c”;
公共静态PixabayImageResponse搜索(字符串搜索)
{
//创建http请求
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(URL+$”?
key={key}&q={search}”);
//设置http方法
request.Method=“GET”;
//发送请求并自动关闭流
使用(HttpWebResponse响应=
(HttpWebResponse)请求。GetResponse()
{
//为响应流创建读取器
StreamReader=新建
StreamReader(response.GetResponseStream());
//将完整响应读入字符串
字符串jsonResponse=reader.ReadToEnd();
//将字符串解析为响应模型对象
PixabayImageResponse PixabayImageResponse=
FromJson(jsonResponse);
//返回结果
返回pixabayImageResponse;
}
}
}

[可序列化]
公共类PixabayImage
{
公共int id;
公共字符串pageURL;
公共字符串类型;
公共字符串标签;
公共字符串预览;
公共int预览宽度;
公众视野;
公共字符串webformatURL;
公共int-webformatWidth;
公共交通高度;
公共字符串largeImageURL;
公共字符串fullHDURL;
公共字符串imageURL;
公共图像宽度;
公众高度;
公共图像大小;
公众意见;
公共int下载;
公众的喜爱;
公众喜欢什么;
公众评论;
公共int用户id;
公共字符串用户;
公共字符串userImageURL;
}
[可序列化]
公共类PixabayImageResponse
{
公共整数合计;
公众点击率;
公开列表点击;
}

可能是HttpWebRequest request=(HttpWebRequest)WebRequest.Create(URL+$”?key={key}&q=“);没有{search}标记?你不能简单地删除搜索栏吗?嘿,谢谢你的回复。正如我所说,我实际上不需要搜索功能,我确实需要它,例如:这是所有页面和检索所有图像的格式。另外,我是这方面的初学者,所以如果我需要将它简化一点,我表示歉意。我知道它需要删除,但这不只是删除html标记吗?。您还可以删除静态PixabayImageResponse搜索(字符串搜索)方法,以澄清您需要的内容。有点模糊。应用程序将有一个不同艺术家的列表。当您选择一个时,下一页将是显示他们工作的图像页面。这些图片将是从一个特定的网站对应的artistFair,如果我是你,我会做一个下拉框。单击下拉框将调用API搜索函数:唯一可行的方法是更改前端HttpWebRequest request=(HttpWebRequest)WebRequest.Create(URL+$”?key={key}&q=“);没有{search}标记?你不能简单地删除搜索栏吗?嘿,谢谢你的回复。正如我所说,我实际上不需要搜索功能,我确实需要它,例如:这是所有页面和检索所有图像的格式。另外,我是这方面的初学者,所以如果我需要将它简化一点,我表示歉意。我知道它需要删除,但这不只是删除html标记吗?。您还可以删除静态PixabayImageResponse搜索(字符串搜索)方法,以澄清您需要的内容。有点模糊。应用程序将有一个不同艺术家的列表。当您选择一个时,下一页将是显示他们工作的图像页面。这些图片将是从一个特定的网站对应的artistFair,如果我是你,我会做一个下拉框。单击下拉框将调用API搜索函数:实现这一点的唯一方法是更改前端
[Serializable]
public class PixabayImage
{
public int id;
public string pageURL;
public string type;
public string tags;
public string previewURL;
public int previewWidth;
public int previewHeight;
public string webformatURL;
public int webformatWidth;
public int webformatHeight;
public string largeImageURL;
public string fullHDURL;
public string imageURL;
public int imageWidth;
public int imageHeight;
public int imageSize;
public int views;
public int downloads;
public int favorites;
public int likes;
public int comments;
public int user_id;
public string user;
public string userImageURL;
}

[Serializable]
public class PixabayImageResponse
{
public int total;
public int totalHits;
public List<PixabayImage> hits;
}