开发者

Returning objects with Jayrock

开发者 https://www.devze.com 2023-04-11 12:37 出处:网络
I am using Jayrock to form a web service in .NET for my iOS app and I\'m following this tutorial. This is all good and I can get it to work fine returning basic strings using code like this:

I am using Jayrock to form a web service in .NET for my iOS app and I'm following this tutorial. This is all good and I can get it to work fine returning basic strings using code like this:

[Jayrock.JsonRpc.JsonRpcMethod("Echo")]
[Jayrock.JsonRpc.JsonRpcHelp("Simple echo method, takes string input and returns it")]
public string Echo(string input)
{
    return in开发者_运维百科put;
}

When it comes to writing my actual web service, how to I get it to return a custom JSON object with numbers and arrays etc? If you could give a code example too that would be awesome.

I've had a google around and a search here, but haven't really been able to find much that helps me. I know it's a basic question, but I'm totally stumped!


All sorted now. I just needed to define a class and return an object from the function, like this:

[Jayrock.JsonRpc.JsonRpcMethod("GetPerson")]
public object GetPerson(string name, int age)
{
    person foo = new person(name, age);
    return foo;
}

public class person
{
    public string Name;
    public int Age;
    public person() { }
    public person(string name, int age)
    {
        Name = name;
        Age = age;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号