Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 554
daniel Avatar asked Oct 25 '25 06:10

daniel


2 Answers

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);
like image 108
Smitty-Werben-Jager-Manjenson Avatar answered Oct 27 '25 20:10

Smitty-Werben-Jager-Manjenson


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 }";

like image 24
P.Brian.Mackey Avatar answered Oct 27 '25 20:10

P.Brian.Mackey