How do I format cookies into JSON?
skausky opened this issue · 1 comments
I noticed you have a JSON class but I'm not sure how to use it.
The DynamicJsonConverter
is currently only there for the deserialization of JSON strings. I will maybe add an option to convert browser information to JSON in the next version tho.
To serialize data into JSON string I would recommend using a library like Newtonsoft.Json
Tutorials:
https://www.newtonsoft.com/json/help/html/SerializingJSON.htm
https://riptutorial.com/json-net/example/6594/how-to-serialize-an-object-to-json-using-json-net-in-csharp
Basically, you just create a class that stores arrays like that:
public class StoredData
{
public Blink.Cookie[] StoresBlinkCookies { get; set; }
public Gecko.Bookmark[] StoresGeckoBookmarks { get; set; }
public Blink.Login[] StoresBlinkLogins { get; set; }
}
Then you just set the Arrays and call a Serialize method like this one (The method depends on what JSON converter you use but it's generally something like this):
StoredData sd = new StoredData() // Store data in class
{
StoredBlinkCookies = _cookies,
StoresGeckoBookmarks = _bookmarks,
StoresBlinkLogins = _logins
};
string json = JsonConvert.SerializeObject(sd); // Convert class to JSON string
Another option would be to create a string in C# and add the values in (However, this is only efficient if you have little data):
string json = $"{\"{cookie.Name}\": \"{cookie.Value}\", \"{cookie.Name}\": \"{cookie.Value}\"}";