c# - Unity C# 如何使用 JSON 实用程序从 http 服务器读取 Json 数据
问题描述
我真的需要从以下位置读取 Json 数据: https ://api.iextrading.com/1.0/stock/aapl/batch?types=quote,news,chart&range=1m&last=10
不幸的是,因为我是初学者,所以我并不真正了解有关 Json Utility 的参考文档。有人可以帮我将数据从 Json 传递到 c#。
json数据:
{
"quote": {
"symbol": "AAPL",
"companyName": "Apple Inc.",
"primaryExchange": "Nasdaq Global Select",
"sector": "Technology",
"calculationPrice": "close",
"open": 189.1,
"openTime": 1526304600392,
"close": 188.15,
"closeTime": 1526328000294,
"high": 189.53,
"low": 187.86,
"latestPrice": 188.15,
"latestSource": "Close",
"latestTime": "May 14, 2018",
"latestUpdate": 1526328000294,
"latestVolume": 15201663,
"iexRealtimePrice": 188.17,
"iexRealtimeSize": 100,
"iexLastUpdated": 1526327999941,
"delayedPrice": 188.15,
"delayedPriceTime": 1526328000294,
"previousClose": 188.59,
"change": -0.44,
"changePercent": -0.00233,
"iexMarketPercent": 0.03066,
"iexVolume": 466083,
"avgTotalVolume": 34166845,
"iexBidPrice": 0,
"iexBidSize": 0,
"iexAskPrice": 0,
"iexAskSize": 0,
"marketCap": 924783214700,
"peRatio": 19.34,
"week52High": 190.37,
"week52Low": 142.2,
"ytdChange": 0.10092655711038234
}
}
我开始编写一些代码来获取 json 字符串,但我无法解析它。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class DataManager : MonoBehaviour
{
public string Index_name;
public string URL;
public string jsonString;
// Update is called once per frame
void Update()
{
URL = "https://api.iextrading.com/1.0/stock/" + Index_name + "/batch?types=quote,news,chart&range=1m&last=10";
}
public void Text_Changed(string newIndex)
{
Index_name = newIndex;
}
public void Request()
{
WWW request = new WWW(URL);
StartCoroutine(OnResponse(request));
}
private IEnumerator OnResponse(WWW req)
{
yield return req;
jsonString = req.text;
}
解决方案
推荐阅读
- ngrok - NGROK 不适用于 WAN 或外部本地网络
- c# - 如何列出可以添加到 C# Appium 框架中的设备和 ios,以使其每次测试都使用不同的 Ios 设备和 Ios OS
- reactjs - Redux mapDispatchToProps 方法不起作用
- mysql - Nodejs 续集读取器/写入器异步操作
- asp.net - NuGet 包需要在构建之前恢复。NuGet MSBuild 目标缺失,构建时需要
- python - Peewee 关节不返回所有选定的字段
- r - 在ggplot中,如何在左对齐的同时将文本定位在最右端?
- ubuntu - Thunderbird 在 Ubuntu 上留下开放线程并通过 Dock 变得无法访问
- java - 从 Android Studio Java 中的 url 获取 datePublished
- python - 未访问 Django“渲染” Pylance