- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 JMS 序列化程序。当 JsonSerializer 与 Doctrine ArrayCollection 类型一起工作时,它给了我不正确的数组格式。指定的结果应遵循格式 [ {}, {} ]
但它给了我 { 1: {}, 2: {} }
.
有关此方案的其他信息。它仅在我尝试序列化包含包含 ArrayCollection 的对象且 ArrayCollection 包含第一级对象的对象时发生。例如:
{
"description":"Text provided",
"date":"1434145921000",
"oid":1,
"userCreator":{
"username":"name123",
"password":"psw",
"oid":2,
"name":"the-name",
"lastname":"the-lasname",
"announcements":{
"1":{
"description":"Clases de inglés",
"date":"1434745921000",
"oid":3
},
"2":{
"description":"Reparar ordenador",
"date":"1434145921000",
"oid":5
}
}
}
}
{
"username":"user1",
"password":"123",
"oid":2,
"name":"Rafael",
"lastname":"Jimenez"
"announcements":[
{
"description":"Cargar cajas a la guardilla",
"date":"1434145921000",
"oid":1
},
{
"description":"Contar césped y quitar malas hierbas",
"date":"1434745921000",
"oid":3
},
{
"description":"Reparar ordenador",
"date":"1434145921000",
"oid":5
}
]
}
最佳答案
您需要重置 ArrayCollection 数组中的键:
$associative = new ArrayCollection([0 => 1, 2 => 1]);
$list = new ArrayCollection($associative->getValues());
If your array is not indexed with a sequence from 0 to count($array) - 1, getting an JS object rather than an array is the expected behaviour, because this is how associative arrays need to be converted to JSON. And if keys are not such sequence, your array is a map, not a list.
php > echo json_encode([0 => 1, 1 => 1]);
[1,1]
php > echo json_encode([0 => 1, 2 => 1]);
{"0":1,"2":1}
关于json - JMS 将 ArrayCollection 序列化为对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30821680/
出于好奇,我尝试了一些原型(prototype)制作,但似乎只允许在第一个位置使用子例程的原型(prototype) &。 当我写作时 sub test (&$$) { do_somethin
我需要开发一个类似于 Android Play 商店应用程序或类似 this app 的应用程序.我阅读了很多教程,发现几乎每个教程都有与 this one 类似的例子。 . 我已经开始使用我的应用程
考虑一个表示“事件之间的时间”的列: (5, 40, 3, 6, 0, 9, 0, 4, 5, 18, 2, 4, 3, 2) 我想将这些分组到 30 个桶中,但桶会重置。期望的结果: (0, 1,
我是一名优秀的程序员,十分优秀!