Cannot convert Dictionary<string, Dictionary<string, string>> to JsonObject in C#

I am trying to return JsonObject as the interface of my method is – public Task<ServiceResult<JsonObject>> GetTranslation(string language); but my test fails at expectedData: var apiResponse = new Dictionary<string, Dictionary<string, string>>() { { "PAGE_NAME", new Dictionary<string, string>() { { "KEY_NAME", "LOCALE IN PARAMETER LANGUAGE" }, { "COPY_TO_CLIPBOARD", "Copy to clipboard" } } } }; var… Read More Cannot convert Dictionary<string, Dictionary<string, string>> to JsonObject in C#

Unable to serialize instance variable of a non-serializable superclass from the serializable subclass

New to this topic and right now I’m stuck at a brick wall. I have 2 classes, parent class: Controller.java and subclass: GreenhouseControls.java. I need to serialize a GreenhouseControls object but also an instance variable (eventList) from its superclass Controller.java. My serialization happens when an inner class of GreenhouseControls.java throws a custom ControllerException, which is… Read More Unable to serialize instance variable of a non-serializable superclass from the serializable subclass

How to serialize a dictionary to an array of json objects

I have a dictionary as shown below: var tableData = new Dictionary<string, string>(); tableData["name"] = "Sam"; tableData["city"] = "Wellington"; tableData["country"] = "New Zealand"; How can I convert the above dictionary to a serialized json data as below: [ { "key": "name", "val": "Sam" }, { "key": "city", "val": "Wellington" }, { "key": "country", "val": "New… Read More How to serialize a dictionary to an array of json objects

SerializeField/Serializable doesn't work for list of custom class (List<customClass>)

Problem: my list of custom class (public List<ComponentClass> OnCast_Comp = new List<ComponentClass>();) doesn’t appear in the unity editor. I already have [SerializeField] above it, with the custom class having [System.Serializable] also above it. But it still wouldn’t show up in the editor. SpellHolder.cs: public class SpellHolder : MonoBehaviour { // holds the currently owned spells… Read More SerializeField/Serializable doesn't work for list of custom class (List<customClass>)

How to serialize an item with an attribute without having child items in C#

I am trying to generate this simplified xml snippet below. <?xml version="1.0" encoding="utf-16"?> <group> <name attr="yes">My name</name> </group> When I serialize the below code the attribute goes to the group but I want the attribute to go to the name. // C# class [XmlRoot("group", IsNullable = false)] public class Test1 { [XmlAttribute] public string attr… Read More How to serialize an item with an attribute without having child items in C#

Select field serialize not working via ajax

I have 3 select menus. I need to send the values over ajax as an array which I’m attempting to do using serialize(). The problem is that it’s only sending 1 value instead of all 3. Any ideas what’s going on? var menu = $(‘select[name^=”menu”]’).serialize(); console.log(menu); <script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js”></script&gt; <select name=”menu[]”> <option value=”test”>test</option> </select> <select name=”menu[]”>… Read More Select field serialize not working via ajax