daniel
daniel

Reputation: 35733

writing json string to firestore in c#

I have a json string:

var jsonstr = "{ 'property1: 'myvalue','property2':2 }";
JObject json2 = JObject.Parse(jsonstr);

and want to write to firestore but the values are empty arrays instead of the values.

var task = collection.Document("test2").SetAsync(json2);

Upvotes: 4

Views: 1060

Answers (2)

P.Brian.Mackey
P.Brian.Mackey

Reputation: 44285

The json is missing a closing ' character on property1. Technically, you should be using double quotes instead of single on JSON.

var jsonstr = "{ 'property1': 'myvalue','property2':2 }";

Upvotes: 1

NewtonSoft JSON : https://www.newtonsoft.com/json

You're going to want to Serialize your object.

var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
var text = JsonConvert.SerializeObject(configuration, settings);

Upvotes: 2

Related Questions