以json为对象很容易,但是不知道我的代码发生了什么。
所以我想使用PHP读取图像元数据(最重要的是图像创建的日期时间),但是iPhone和其他电话不发送带有图像的此信息,如果尝试使用PC上载则可以正常工作。但是如果图像被压缩,那么我们将丢失所有元数据。
因此,使用php读取元数据并没有用,然后我决定通过JavaScript进行读取,因此我使用的是exif.js。
对于多次上传,一切正常,但是当我尝试将对象转换为json时,我得到的是空字符串。
这是我的代码
Sub CreateAndNameWorksheets()
Dim c As Range
Dim ws As Worksheet: Set ws = Sheets("List")
Dim sh As Worksheet
Dim FoundSh As Boolean
Application.ScreenUpdating = False
LastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
'get last row with data on Column B
For Each c In ws.Range("B5:B" & LastRow) 'loop through row 1 to Last
For Each sh In ThisWorkbook.Worksheets 'loop through Worksheets
If c.Value = sh.Name Then FoundSh = True 'if it exists set flag as found
Next sh
If FoundSh = False Then 'if it wasn't found then create it
Sheets("Template").Copy After:=Sheets(Sheets.Count)
With c
ActiveSheet.Name = .Value
.Parent.Hyperlinks.Add Anchor:=c, Address:="", SubAddress:= _
"'" & .Text & "'!A1", TextToDisplay:=.Text
End With
End If
FoundSh = False 'reset flag for next loop
Next c
Application.ScreenUpdating = True
Call SheetKiller
Call Test
End Sub
Sub SheetKiller()
Dim rList As Range, s As String, sh As Worksheet
Dim KillIt As Boolean, r As Range
Sheets("List").Activate
Set rList = Range("B1:B200")
Application.DisplayAlerts = False
On Error Resume Next
For Each sh In Sheets
s = sh.Name
KillIt = True
For Each r In rList
If r.Value = s Then KillIt = False
Next
If KillIt Then sh.Delete
Next
Application.DisplayAlerts = True
End Sub
Sub Test()
Dim i As Long
With Sheets("List")
For i = 5 To .Range("B" & .Rows.Count).End(xlUp).Row
.Hyperlinks.Add Anchor:=.Range("B" & i), Address:="", _
SubAddress:="'" & .Range("B" & i).Value & "'!A1", TextToDisplay:=.Range("B" & i).Value
Next i
End With
End Sub
$('#ServicePhotos').change(function(){
$('#err_msg').html('');
var objects = {};
var lg = this.files.length;
for(var i = 0; i < lg; i++){
(function(file){
var file = file;
var file_path = file.name;
if(file_path){
var startIndex = (file_path.indexOf('\\') >= 0 ? file_path.lastIndexOf('\\') : file_path.lastIndexOf('/'));
var filename = file_path.substring(startIndex);
if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) {
filename = filename.substring(1); }
//console.log('uploading image ' + filename);
}
EXIF.getData(file, function() {
var exifData = EXIF.pretty(this);
if (exifData) {
var allMetaData = EXIF.getAllTags(this);
var DateTime = EXIF.getTag(this, "DateTime");
objects[filename] = {'created':DateTime};
}
});
})(this.files[i]);
}
console.log(objects); /*showing all data */
var myJSON = JSON.stringify(objects);
console.log(myJSON); /* EMPTY ??? */
$('#err_msg').html(myJSON);
$('#meta_data').val(myJSON);
});
现在,此处的“ var myJSON”未显示json数据
这是console.log
答案 0 :(得分:0)
如果无法字符串化,则可能意味着您的对象没有可枚举属性。您可以测试对象属性是否为enumerable,如果为true,则应该可以使用JSON.stringify()
来自 MDN网络文档(https://developer.mozilla.org):
“ 所有其他Object实例(包括Map,Set,WeakMap和WeakSet)将仅对其可枚举的属性进行序列化。”
摘自文档:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify