0

我在visual studio 2017中使用c#创建了一个aws lambda函数,我遇到了参数问题。我试图得到'querystring参数' 但每次我在我的FunctionHandler中的一个参数,我得到这个错误。AWS Lambda中的JsonReaderException C#函数

{ 
    "errorType": "JsonReaderException", 
    "errorMessage": "Unexpected character encountered while parsing value: {. Path '', line 1, position 1.", 
    "stackTrace": [ 
    "at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)", 
    "at Newtonsoft.Json.JsonTextReader.ReadAsString()", 
    "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)", 
    "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)", 
    "at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)", 
    "at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)", 
    "at lambda_method(Closure , Stream , Stream , ContextInfo)" 
    ] 
} 

这是我的示例代码FunctionHandler:

public string FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context) 
     { 
      var sample = GetParameters(request.QueryStringParameters, "sample"); 
      return sample; 
     } 

这有什么错呢?答案将非常感激。谢谢 !

UPDATE

Error Message

+0

什么是你输入的输入拉姆达? – Kannaiyan

+0

我通过API网关传递查询参数。 – anonymous

+0

您能否请您提供如何传递参数,我的意思是JSON值的格式 – msoliman

回答

1

的异常意味着你不通过你的参数作为有效JSON格式。请确保以字符串引用的格式传递参数。

public string myFunctionHandler(string param, ILambdaContext context){ 
.... 
} 

传递参数(在字符串中引用格式)应该看起来像:

"{ \"param\": \"value\" }" 

如果你有一个对象:

public string myFunctionHandler(JObject param, ILambdaContext context) { 
... 
} 

在这种情况下,你可以通过它像这:

{ "param": "value" } 
+0

如果我想将它作为查询参数传递,但不通过AWS API网关?喜欢,http://api.com/v1?param=sample ... – anonymous

+0

@anonymous这样的查询参数映射可以配置为提到http://docs.aws.amazon.com/apigateway/latest/developerguide/how-到方法 - 设置 - 执行 - console.html –