我正在尝试使用ijson包解析一个大的(~100MB)json文件,它允许我以有效的方式与文件交互.但是,在编写了这样的代码之后,
with open(filename, 'r') as f:
parser = ijson.parse(f)
for prefix, event, value in parser:
if prefix == "name":
print(value)
Run Code Online (Sandbox Code Playgroud)
我发现代码只解析第一行,而不解析文件中的其余行!
以下是我的json文件的一部分:
{"name":"accelerator_pedal_position","value":0,"timestamp":1364323939.012000}
{"name":"engine_speed","value":772,"timestamp":1364323939.027000}
{"name":"vehicle_speed","value":0,"timestamp":1364323939.029000}
{"name":"accelerator_pedal_position","value":0,"timestamp":1364323939.035000}
Run Code Online (Sandbox Code Playgroud)
在我看来,我认为ijson只解析一个json对象.
有人可以建议如何解决这个问题?
我创建了一个实体文档,其中包含包括文件属性在内的属性列表,同时添加文档进展顺利,当我更新时,我收到验证错误:
找不到该文件。
文件属性在添加时必须是必需的,但在编辑时是可选的,因为我可以只保留旧文件。
这是我的实体文档的一部分:
/**
* @ORM\Entity
* @ORM\Table(name="document")
*/
class Document
{
...
/**
* @var string
* @Assert\NotBlank()
* @Assert\File(maxSize = "5M", mimeTypes = {"application/pdf"})
* @ORM\Column(name="file", type="string", length=255, nullable=true)
*/
private $file;
/**
* @var string
* @ORM\Column(name="name", type="string", length=50)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity="Dtype", inversedBy="documents")
*/
private $dtype;
...
public function uploadFile($path, $type='', $oldFile=null)
{
$file = $this->getFile();
if ($file instanceof UploadedFile) {
if(!empty($type)){
$path = $path. '/' . $type;
} …Run Code Online (Sandbox Code Playgroud)