2016-07-02 18 views
1

私は、スパイダーでスパイダーを構築しました。私はそれを実行し、以下に示すようにjsonファイルに出力します。次に、VBAでclsJsonParserを使用し、次のコードを使用しています。しかし、私はelement.item( "newstxt")の3265エラー "このコレクションには見つかりません"を取得しています。 element.item( "newstitle")はうまく動作します。何がうまくいかないのですか?それは私のVBAコード、または私のjsonファイルのフォーマットですか?VBA JsonParser clsJsonParserが機能しません

Public Sub JSONImport() 
Dim coll As Collection 
Dim json As New clsJSONparser 
Dim db As DAO.Database 
Dim rs As DAO.Recordset 
Dim element As Variant 

Dim FileNum As Integer 
Dim DataLine As String, jsonStr As String 

' READ FROM EXTERNAL FILE 
FileNum = FreeFile() 
Open "C:\Users\Philippe\sfo\unepinquiry\items.json" For Input As #FileNum 

' PARSE FILE STRING 
jsonStr = "" 
While Not EOF(FileNum) 
    Line Input #FileNum, DataLine 

    jsonStr = jsonStr & DataLine & vbNewLine 
Wend 
Close #FileNum 

    Set db = CurrentDb 
    Set rs = db.OpenRecordset("News_1", dbOpenDynaset, dbSeeChanges) 
    Set coll = json.parse(jsonStr) 

    For Each element In coll 
     rs.AddNew 
     rs!newstitle = element.item("newstitle") 
     rs!newstxt = element.item("newstxt") 
     rs.Update 
    Next 


Set element = Nothing 
Set coll = Nothing 

End Subの

[{ "newstxt":[ "2016年6月21日には、G20グリーン・ファイナンス研究会の第4回会合は、アモイで開催された会議が共同でホストされました。 G20諸国の代表者、招待された加盟国および国際機関が参加し、G20グリーン・ファイナンス・シンセシス・レポートに関する原則的な議論と合意を得た。 6月のG20財務大臣および中央銀行代理人のアモイ会合を検討し、7月のG20財務大臣およびCe 」、「newstitle」:「G20グリーンファイナンス研究会の第4回会議が厦門で終了\ n」}、 {"newstxt":[ムンバイ、2016年4月29日、\ u00a0-インドは追加的な低コストの長期的な資本の動員を必要とする包括的で持続可能な開発の野心的な目標を設定する。国連環境計画(UNEP)とインド商工会議所連盟(FICCI)が最近発表した新しい報告書では、グリーン資産のために民間資本を誘致するための革新的なアプローチを既に導入していることが示されており、インドではこのプロセスを深めるための手順 "]、『newstitle。』:『\ n新規報告書は、』インドは持続可能な財政の\ nをスケールアップする方法を示し}]

答えて

1

は言うことはできませんが、このテスト関数を実行した場合:JSONモジュールを使用して

Public Sub TestJsonText() 

    Dim DataCollection  As Collection 
    Dim ResponseText  As String 

    ResponseText = _ 
     "[{""newstxt"": [""On June 21, 2016, the fourth meeting of the G20 Green Finance Study Group was held in Xiamen. The meeting was hosted by Co-chairs from the People's Bank of China and the Bank of England. Delegates from G20 countries, invited guest countries and International Organizations participated in the meeting. The delegates discussed and agreed in principle on the G20 Green Finance Synthesis Report, which would be submitted to the June G20 Finance and Central Bank Deputies Xiamen Meeting. The study group will further revise and submit the Report to the July G20 Finance Ministers and Central Bank Governors Chengdu Meeting.""]," & _ 
     """newstitle"": ""\nFourth Meeting of the G20 Green Finance Study Group Concludes in Xiamen\n""}, " & _ 
     "{""newstxt"": [""Mumbai, 29 April 2016\u00a0- India has set ambitious goals for inclusive and sustainable development, which require the mobilization of additional low-cost, long-term capital. A new report launched today by the United Nations Environment Programme (UNEP) and the Federation of Indian Chambers of Commerce and Industry (FICCI) shows how the country is already introducing innovative approaches to attract private capital for green assets - and outlines a number of key steps to deepen this process in India.""]," & _ 
     """newstitle"": ""\nNew Report Shows How India Can Scale up Sustainable Finance\n""}]" 
    If ResponseText <> "" Then 
     Set DataCollection = CollectJson(ResponseText) 
     MsgBox "Retrieved" & Str(DataCollection.Count) & " root member(s)", vbInformation + vbOKOnly, "Web Service Success" 
    End If 

    Call ListFieldNames(DataCollection) 

    Set DataCollection = Nothing 

End Sub 

ここで見つける:VBA.CVRAPI

それが印刷されます:私には正しいよう

root       
    0      
     newstxt    On June 21, 2016, the fourth meeting of the G20 Green Finance Study Group was held in Xiamen. The meeting was hosted by Co-chairs from the People's Bank of China and the Bank of England. Delegates from G20 countries, invited guest countries and International Organizations participated in the meeting. The delegates discussed and agreed in principle on the G20 Green Finance Synthesis Report, which would be submitted to the June G20 Finance and Central Bank Deputies Xiamen Meeting. The study group will further revise and submit the Report to the July G20 Finance Ministers and Central Bank Governors Chengdu Meeting. 
     newstitle   
Fourth Meeting of the G20 Green Finance Study Group Concludes in Xiamen 

    1      
     newstxt    Mumbai, 29 April 2016 - India has set ambitious goals for inclusive and sustainable development, which require the mobilization of additional low-cost, long-term capital. A new report launched today by the United Nations Environment Programme (UNEP) and the Federation of Indian Chambers of Commerce and Industry (FICCI) shows how the country is already introducing innovative approaches to attract private capital for green assets - and outlines a number of key steps to deepen this process in India. 
     newstitle   
New Report Shows How India Can Scale up Sustainable Finance 

を。だからおそらくclsJSONparserあなたが調査する必要があります。

関連する問題