考虑以下代码:
vector<string> parse(char* _config) {
ifstream my_file(_config);
vector<string> my_lines;
string nextLine;
while (std::getline(my_file, nextLine)) {
if (nextLine[0] == '#' || nextLine.empty() || nextLine == "") continue;
my_lines.push_back(nextLine);
}
return my_lines;
}
Run Code Online (Sandbox Code Playgroud)
和这个配置文件:
#Verbal OFF
0
#Highest numeric value
100
#Deck
67D 44D 54D 63D AS 69H 100D 41H 100C 39H 10H 85H 7D 42S 6C 67H 61D 33D 28H 93S QH 5D 91C 40S 50C 74S 8C 98C 96C 71D 82S 75S 23D 40C 29S QC 84C 16C 80D 13H …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下方法从用户加载JSON文件:
<input
style="display: none"
type="file" (change)="onFileChanged($event)"
#fileInput>
<button (click)="fileInput.click()">Select File</button>
<button (click)="onUpload()">Upload!</button>
Run Code Online (Sandbox Code Playgroud)
这是组件ts文件中的代码:
export class MyFileUploadComponent {
selectedFile: File
onFileChanged(event) {
this.selectedFile = event.target.files[0];
console.log(this.selectedFile);
console.log('content: ' + JSON.stringify(this.selectedFile));
}
onUpload() {
// upload code goes here
}
}
Run Code Online (Sandbox Code Playgroud)
该行console.log(this.selectedFile);的确为我提供了文件元数据,即:
lastModified: 1551625969247
lastModifiedDate: Sun Mar 03 2019 17:12:49 GMT+0200 (Israel Standard Time) {}
name: "manuscripts.json"
size: 6008
type: "application/json"
webkitRelativePath: ""
__proto__: File
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用它JSON.stringify获取内容时,会得到:({}空文件)。
是什么原因
谢谢。