2017-10-27 6 views
0

JSON文字列をAzureテーブルストレージの列に変換するために、以下のコードを使用しました。azureテーブルのjson文字列から列へ

2017-10-27T06:27: Functions.fnConvertJsonToTable:実行機能、一方02.134例外

'use strict'; 
// This function is triggered each time a message is received in the IoT hub. 
// The message payload is persisted in an Azure storage table 

module.exports = function (context, iotHubMessage) 
{ 
    context.log('Message received: ' + JSON.stringify(iotHubMessage)); 
    var date = Date.now(); 
    var deviceData = { 
     "partitionKey": Math.floor(date/(24 * 60 * 60 * 1000)) + '', 
     "rowKey": date + '', 
    }; 

    Object.keys(iotHubMessage).forEach(function(key) { 
     deviceData[key] = iotHubMessage[key]; 
    }); 

    context.bindings.outputTable = deviceData; 
    context.done(); 
}; 

これはまだ以下のように失敗したことを示しています。 Microsoft.Azure.WebJobs.Host:エラー 関数が返された後にパラメータ_binderを処理しているとき: Microsoft.WindowsAzure.Storage:バッチ内の要素0が、予期しない応答コード を返しました。 2017-10-27T06:27:02.196機能 (失敗、ID = 7870d04d-4cc2-4474-8ffa-d67add613f6c、持続時間= 145ms)

を完了し、正しい解決策を提案してください。 ありがとうございます。

+0

context.log outputTableには何が表示されますか? – Sage

答えて

0

私はできる限りこれを再現しましたが、問題やエラーは発生しませんでした。

module.exports = function (context, req) { 
    context.log('JavaScript HTTP trigger function processed a request.'); 

    if (req.query.name || (req.body && req.body.name)) { 

     var message = req.body; 
     context.log(message); 

     var 
      date = Date.now(), 
      key = Math.floor(date/(24 * 60 * 60 * 1000)); 

     context.log(date); 
     context.log(key); 
     var tableData = { 
      "partitionKey": Math.floor(date/(24 * 60 * 60 * 1000)), 
      "rowKey": date 
     }; 
     Object.keys(message).forEach(function(key) { 
      tableData[key] = message[key]; 
     }); 
     context.log(tableData); 
     context.bindings.outputTable = tableData; 

     context.log("Output Documents Bound"); 

     context.res = { 
      status: 200, /* Defaults to 200 */ 
      body: message 
     }; 

    } 
    else { 
     context.res = { 
      status: 400, 
      body: "Please pass a name on the query string or in the request body" 
     }; 
    } 
    context.done(); 
}; 

Azure Table with Data

私はそれでも、私はエラーを取得didntのものと、あなたがdeviceDataであなたの各変数の末尾に「+ 『』」を持っていた気づきました。

これは、あなたのAzure Table Storage出力バインドに何か問題があるかどうか疑問です。

関連する問題