我有这样的脚本:
trait A[T <: A[T]]
class B {
case class C(int: Int) extends A[C]
def make = C(5)
}
object D {
def foo[T <: A[T]](some: A[T]) = {}
val b = new B
val c: b.C = b.make
foo(c)
}
和json看起来像这样:
import {View, OnInit, Component} from 'angular2/core'
import {MeteorComponent} from 'angular2-meteor'
import {Navbar} from 'client/navbar/navbar'
import {FakePlayground} from 'client/intro/fake-playground/fake-playground'
import {PlayerList} from 'client/player-list/player-list'
import {PlayerService} from 'client/player/player-service'
import {Player} from 'client/player/player'
import {ProtectedDirective} from 'client/directives/protected-directive'
import {SentInvitation} from 'client/invitation/sent-invitation'
import {ReceivedInvitation} from 'client/invitation/received-invitation'
import {Invitations} from 'lib/invitations'
import {Router} from 'angular2/router'
@Component({
selector: 'intro'
})
@View({
templateUrl: 'client/intro/intro.html',
directives: [
Navbar,
PlayerList,
FakePlayground,
ProtectedDirective,
SentInvitation,
ReceivedInvitation
]
})
export class Intro extends MeteorComponent implements OnInit {
currentPlayer: Player
invitation: Mongo.Cursor<Object>
constructor(
public playerService: PlayerService,
private _router:Router
) {
super()
}
getInvitation() {
this.subscribe('invitations', () => {
this.invitation = Invitations.find({$or: [
{$and: [
{"sender._id": this.currentPlayer._id},
{status: 1}
]},
{$and: [
{"recipient._id": this.currentPlayer._id},
{status: 1}
]}
]})
this.autorun(() => {
console.log('autorun')
if(this.invitation){
console.log('game started')
this._router.navigate(['Game'])
}
})
})
}
getPlayer() {
this.currentPlayer = this.playerService.getCurrentPlayer()
}
ngOnInit() {
this.getPlayer()
this.getInvitation()
}
}
我在其他网站上获取json数据,jsonlint注意到json无效
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com/?weather=USA");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
$row = json_decode($result, TRUE);
echo $row['teston'];
?>
我必须做什么才能使我的剧本有效?
编辑:我添加{
"test": ["test1", "test2", "test3"],
"teston": "teston2",
"debug": {}
} {
"test": ["test1", "test2", "test3"],
"teston": "teston2",
"debug": {}
}
之后输出:
Error: Parse error on line 5:
...n2", "debug": {}} { "test": ["test1",
---------------------^
Expecting 'EOF', '}', ',', ']', got '{'
我使用以下代码从XML转换json:
var_dump($result);
我的php转换代码有问题吗? 在我的脚本中包含这样的循环:
string(1204) "{
"test": ["test1", "test2", "test3"],
"teston": "teston2",
"debug": {}
} {
"test": ["test1", "test2", "test3"],
"teston": "teston2",
"debug": {}
}"
如何$ this-&gt; params为$ key =&gt; $ val没有循环?有可能吗?