0

Im using NewtonSoft linq 2 json to serialize objects from classes straight to a json string

The class object I'm using is very simple :

public class OverviewQuery
{
    public string id { get; set; }
    public string method { get; set; }
    public string Params { get; set; }

    public OverviewQuery(string sid, string smethod, string sparam)
    {
        this.id = sid;
        this.method = smethod;
        this.Params = sparam;
    }
}

If I serialise this, I get the Json string :

"{\"id\":\"1\",\"method\":\"getStockItemDetails\",\"Params\":\"0000000002\"}"

The Oracle server I'm connecting to (through WebAPI's) requires me to use very very specific naming, here it should be

"{\"id\":\"1\",\"method\":\"getStockItemDetails\",\"Params\":[\"0000000002\"]}"

Is there any way NewtonSoft implemented a way to achieve this formatting ? Without correct formatting, the only way to send the information is through hardcoding everything..

NoxBene
  • 94
  • 1
  • 12
  • I am temporarely fixing this issue by added a databound string in between the already formatted query, partially hardcoded in other words.. "{\"id\":\"1\",\"method\":\"getStockItemDetails\",\"Params\":[\""+idref+"\"]}" This works .. but is a very sleazy way to write code .. – NoxBene Apr 26 '12 at 12:21

1 Answers1

0

What the serialiser is doing with your class seems straightforward.

Generally JSON-RPC services will require that the params value in the envelope be a JSON Array (for indexed parameters) or an Object (for named parameters).

Could you just change your class such that Params is an Array of String ?

David-SkyMesh
  • 5,041
  • 1
  • 31
  • 38