dream6120 2011-06-01 11:22
浏览 59
已采纳

如何将PHP JSON Web服务转换为C#?

I've been writing an iPhone app that could send JSON to a PHP file and been fairly successful doing this. However, now that I want to move on to ASP C# and create an equivalent .NET web service akin to the PHP I wrote earlier to decode and encode the JSON, I'm completely clueless.

In PHP I do this:

$handle = fopen('php://input','r');
$jsonInput = fgets($handle);
$decoded = json_decode($jsonInput,true);

to receive the JSON POST data and decode it . Then using this:

$data = $decoded;
header('Content-Type: application/json');
echo json_encode($data);

How do I write an equivalent C# web service? Thanks.

  • 写回答

1条回答 默认 最新

  • douzhi7070 2011-06-01 11:29
    关注

    It very simple to use WCF REST. follow steps as this link below:

    http://blogs.msdn.com/b/kaevans/archive/2008/04/03/creating-restful-services-using-wcf.aspx

    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebGet(UriTemplate="customers/{id}", ResponseFormat=WebMessageFormat.Json)]
        Customer GetCustomer(string id);
    
        [OperationContract]
        [WebInvoke(UriTemplate="customers", ResponseFormat=WebMessageFormat.Json)]
        Customer PostCustomer(Customer c);
    }
    

    so result will get in Json format encode by WCF.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上