正确格式化php输出
我做了一些研究,但找不到我要找的东西。 我远非PHP专家,但我认为我正在尝试做一些相当简单的事情 在Unity3D中,我希望从PHP输出中接收几个值,我通过post请求获得这些值 输出来自arangoDB,如下所示:正确格式化php输出,php,arrays,string,unity3d,arangodb,Php,Arrays,String,Unity3d,Arangodb,我做了一些研究,但找不到我要找的东西。 我远非PHP专家,但我认为我正在尝试做一些相当简单的事情 在Unity3D中,我希望从PHP输出中接收几个值,我通过post请求获得这些值 输出来自arangoDB,如下所示: array(1) { [0]=> object(ArangoDBClient\Document)#9 (9) { ["_id":protected]=> string(16) "Producten/140368" ["_key":prot
array(1) {
[0]=>
object(ArangoDBClient\Document)#9 (9) {
["_id":protected]=>
string(16) "Producten/140368"
["_key":protected]=>
string(6) "140368"
["_rev":protected]=>
string(11) "_WMOJhJe--_"
["_values":protected]=>
array(3) {
["Naam Product"]=>
string(9) "Naam-Foo2"
["Categorie Product"]=>
string(14) "Categorie-Foo2"
["Discipline Product"]=>
string(15) "Discipline-Foo2"
}
["_changed":protected]=>
bool(true)
["_isNew":protected]=>
bool(false)
["_doValidate":protected]=>
bool(false)
["_hiddenAttributes":protected]=>
array(0) {
}
["_ignoreHiddenAttributes":protected]=>
bool(false)
}
}
Naam Product: Naam-Foo2;
Categorie Product: Categorie-Foo2;
Discipline Product: Discipline-Foo2;
我只对这部分感兴趣:
["Naam Product"]=>
string(9) "Naam-Foo2"
["Categorie Product"]=>
string(14) "Categorie-Foo2"
["Discipline Product"]=>
string(15) "Discipline-Foo2"
最佳案例场景它的格式如下:
array(1) {
[0]=>
object(ArangoDBClient\Document)#9 (9) {
["_id":protected]=>
string(16) "Producten/140368"
["_key":protected]=>
string(6) "140368"
["_rev":protected]=>
string(11) "_WMOJhJe--_"
["_values":protected]=>
array(3) {
["Naam Product"]=>
string(9) "Naam-Foo2"
["Categorie Product"]=>
string(14) "Categorie-Foo2"
["Discipline Product"]=>
string(15) "Discipline-Foo2"
}
["_changed":protected]=>
bool(true)
["_isNew":protected]=>
bool(false)
["_doValidate":protected]=>
bool(false)
["_hiddenAttributes":protected]=>
array(0) {
}
["_ignoreHiddenAttributes":protected]=>
bool(false)
}
}
Naam Product: Naam-Foo2;
Categorie Product: Categorie-Foo2;
Discipline Product: Discipline-Foo2;
如何过滤这些信息,以便在Unity中读取时获得干净的数据字符串
有什么建议吗?先进的Thnx 尝试使用
getAll
方法:
$interested_array = $filter[0]->getAll();
print_r($interested_array);
就我而言,最好将
JSON
数据从服务器发送到客户端。只需将库添加到您的Unity3D
项目中即可。然后,您可以轻松地将接收到的json字符串反序列化为C#对象。下面是一个简单的例子:
string jsonString = "Your json string";
var deserializedObject = Newtonsoft.Json.JsonConvert.DeserializeObject<YOUR_POCO_OBJECT>(jsonString);
它给了我这个错误:致命错误:未捕获错误:无法使用ArangodClient\Cursor类型的对象作为C:\xampp\htdocs\ArangoTest\index.php中的数组。php:62堆栈跟踪:#0{main}抛出在C:\xampp\htdocs\ArangoTest\index.php的第62行,我删除了[],现在它输出的结果已经稍微干净了一点!它看起来像是一个数组中的一个数组。你是怎么过滤的?是的,我想你是对的。我已经读过了,但是我想在我可以从我的php发送json字符串之前,我必须将它清理到我需要的各个部分?因为现在我有一个简单的数组,我可以将它转换成json,然后在unity中作为json接收。至少这就是我现在要做的:)我添加了echo json_encode($interest_array);现在我有了干净的json作为输出,感谢您的帮助