Reputation: 8643
How do i manually create a JSON object in monotouch(4.0)?
The System.JSON namespace is available, (JsonObject
, JsonArray
, jSonPrimitive
and JsonValue
) but those are all abstract, so i can't just do this :
JsonObject myObject = new JsonObject();
I need to manually build a JSON object, and do not want to use DataContractSerialisation.
For reference purposes :
-I will need to transfer that JSON object to a server with a web call later. (but i can handle that part)
Upvotes: 1
Views: 1123
Reputation: 8643
As it turns out, after a long time of trying and searching ; only the JsonPrimitive
constructor and the JsonObject
constructor can be used.
JsonPrimitive
and JsonValue
can both be cast to JsonValue
.
the JsonObject
requires a KeyValuePair<string, JsonValue>
if i define functions like this :
public static KeyValuePair<String, JsonValue> IntRequired(string key, int val)
{
return new KeyValuePair<String, JsonValue>(key, new JsonPrimitive(val));
}
i can create a json object like this :
JSonObject myObject = new JsonObject();
myObject.add(new IntRequired("id",1));
Upvotes: 1