我正在尝试使用json_decode
函数来获取数据。
结果如下print_r
:
Array
(
[ticker] => Array
(
[base] => BTC
[target] => USD
[price] => 3796.85831297
[volume] => 173261.82951203
[change] => 6.29130608
)
[timestamp] => 1545745501
[success] => 1
[error] =>
)
Run Code Online (Sandbox Code Playgroud)
当我想用 调用价格值时foreach
,它会显示该值,但出现以下错误:
警告:非法字符串偏移“价格”
foreach ($json as $key => $value) {
$price = $value['price'];
echo '<br>' . $price;
}
Run Code Online (Sandbox Code Playgroud)
结果如下var_dump
:
array(4) {
["ticker"]=>
array(5) {
["base"]=>
string(3) "BTC"
["target"]=>
string(3) "USD"
["price"]=>
string(13) "3796.85831297"
["volume"]=>
string(15) "173261.82951203"
["change"]=>
string(10) "6.29130608" …
Run Code Online (Sandbox Code Playgroud) 我正在Unity中开展2D游戏.游戏限制为60秒.我想要一个定时炸弹,当玩家击中炸弹时会导致时间缩短.
在我的脚本中,我有一个名为的布尔值,"hitDetect"
我使用一个Coroutine()
倒计时.
当玩家击中炸弹时我试图将炸弹推到右侧,然后用这些代码检查碰撞是否发生:
void OnCollisionEnter2D(Collision2D bombcol)
{
if(bombcol.gameObject.tag == "Enemy")
{
bombcol.gameObject.GetComponent<Rigidbody2D>().AddForce(transform.right * hitForce);
}
hitDetect = true;
}
Run Code Online (Sandbox Code Playgroud)
这是我的Coroutine()
功能,它让我有一个成功限制为60秒的游戏,除了时间惩罚:
IEnumerator LoseTime()
{
while (true) {
yield return new WaitForSeconds (1);
timeLeft--;
if (hitDetect == true)
{
timeLeft= timeLeft - 5;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还在"hitDetect"
开始体中将其设置为false.
void Start ()
{
StartCoroutine("LoseTime");
hitDetect = false;
}
Run Code Online (Sandbox Code Playgroud)
但是,这些方法并没有让我获得成功.当玩家击中炸弹时,时间惩罚不起作用.我的错误在哪里?你会推荐什么?
我使用这些代码更改了导航栏的默认颜色,app.xaml
因为我无法在 iOS 设备上使其透明:
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="#0a82b8" />
<Setter Property="BarTextColor" Value="#ffffff" />
</Style>
Run Code Online (Sandbox Code Playgroud)
现在,iOS 上有一个不必要的导航栏分隔符:
在微软的官方网站上,它说这些代码可能会有所帮助:
此特定于平台的隐藏位于 NavigationPage 上导航栏底部的分隔线和阴影。它通过将 NavigationPage.HideNavigationBarSeparator 可绑定属性设置为 false 在 XAML 中使用:
Run Code Online (Sandbox Code Playgroud)<NavigationPage ... xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" ios:NavigationPage.HideNavigationBarSeparator="true"> </NavigationPage>
或者,可以使用 fluent API 从 C# 使用它:
Run Code Online (Sandbox Code Playgroud)using Xamarin.Forms.PlatformConfiguration; using Xamarin.Forms.PlatformConfiguration.iOSSpecific; public class iOSTitleViewNavigationPageCS : Xamarin.Forms.NavigationPage { public iOSTitleViewNavigationPageCS() { On<iOS>().SetHideNavigationBarSeparator(true); } }
问题是,当我想将该ios:NavigationPage.HideNavigationBarSeparator="true"
属性粘贴到<NavigationPage>
标签中时,会出现以下错误:
找不到“HideNavigationBarSeparator”的属性、可绑定属性或事件,或者值和属性之间的类型不匹配。
我的完整代码是:
<?xml version="1.0" encoding="utf-8"?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:My.App" x:Class="My.App.MainPage">
<MasterDetailPage.Master>
<ContentPage Title="Menu" BackgroundColor="#0a82b8" Icon="menu.png">
<StackLayout Orientation="Vertical">
<ListView …
Run Code Online (Sandbox Code Playgroud)