Returning a string containing valid Json with Nancy

后端 未结 5 653
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 14:05

I receive a string that contains valid JSON from another service. I would like to just forward this string with Nancy but also set the content-type to \"application/json\" which

5条回答
  •  名媛妹妹
    2021-01-31 15:06

    Looks like Nancy has got a nice Response.AsJson extension method:

    Get["/providers"] = _ =>
                {
                    var providers = this.interactiveDiagnostics
                                        .AvailableDiagnostics
                                        .Select(p => new { p.Name, p.Description, Type = p.GetType().Name, p.GetType().Namespace, Assembly = p.GetType().Assembly.GetName().Name })
                                        .ToArray();
    
                    return Response.AsJson(providers);
                };
    

提交回复
热议问题