Questions tagged [json-serialization]

302 questions
288
votes
4 answers

What is deserialize and serialize in JSON?

I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?
179
votes
9 answers

How do I serialize a C# anonymous type to a JSON string?

I'm attempting to use the following code to serialize an anonymous type to JSON: var serializer = new DataContractJsonSerializer(thing.GetType()); var ms = new MemoryStream(); serializer.WriteObject(ms, thing); var json =…
68
votes
4 answers

Invalid conversion from throwing function of type (_,_,_) throws -> Void to non-throwing function type (NSData?, NSURLResponse?, NSError?) -> Void

I have written this code: func getjson() { let urlPath = "https://api.whitehouse.gov/v1/petitions.json?limit=100" let url = NSURL(string: urlPath) let session = NSURLSession.sharedSession() let task =…
Martin Mikusovic
  • 1,002
  • 2
  • 9
  • 14
39
votes
3 answers

JavaScriptSerializer is not allowed in .net core project?

I am working in .net core project. I want to serialize the objects using JavaScriptSerializer. JavaScriptSerializer Serializer = new JavaScriptSerializer(); I added the namespace using System.Web.Script.Serialization;. It throws errors. I googled…
38
votes
5 answers

Make names of named tuples appear in serialized JSON responses

Situation: I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. For the sake of simplicity, here's an…
Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
28
votes
4 answers

Flag to ignore serialization of property build_runner

Is there a way to ignore the serialization of a property within a JsonSerializable class? I'm using build_runner to generate the mapping code. One way to achieve this is by commenting the mapping for that specific property within the .g.dart-file…
Alex
  • 487
  • 1
  • 6
  • 19
25
votes
14 answers

System.Text.Json.JsonException: The input does not contain any JSON tokens

I'm just trying to use a Http POST method in a Blazor app through public async Task CreateUnit(UnitEntity unit) { await _http.PostJsonAsync("api/units", unit); } _http and myObject have been defined elsewhere, but I'm getting this…
Broad3857
  • 363
  • 1
  • 4
  • 10
14
votes
3 answers

Json serialization of nested dataclasses

I would need to take the question about json serialization of @dataclass from Make the Python json encoder support Python's new dataclasses a bit further: consider when they are in a nested structure. Consider: import json from attr import…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
13
votes
1 answer

ASP.NET Web API: JSON Serializing Circular References

I am retrieving a JSON object graph via ASP.NET Web API. I'm trying to access the properties from a child entity. When looking at the browser's console, however, it is showing a reference ($ref) to the object, instead of serializing the properties…
12
votes
3 answers

net core web api json serialization - need fields prefixed with $

I'm using net core web api and need to return a payload with property name "$skip". I tried using the DataAnnotations: public class ApiResponseMessage { [Display(Name ="$skip", ShortName = "$skip")] public int Skip { get; set; } …
ericsson007
  • 131
  • 1
  • 1
  • 4
11
votes
1 answer

Parse List using json_serializable library in Flutter

Consider the following json: [ { "id": 1 "name": "foo" }, { "id": 1 "name": "foo" } ] I am trying to parse this using json_serializable library. json.decode(response.body) returns List. but the json_serializable auto-generates…
Akshar Patel
  • 8,998
  • 6
  • 35
  • 50
11
votes
1 answer

json_serializable enum values in dart

I'm new to dart development... I can't figure out how to use the Json_serializable package with enum types. my database has the enum values as an integer, but it looks like JSON_Serializable wants the value to be a string representation of the enum…
cjmarques
  • 632
  • 1
  • 7
  • 17
8
votes
2 answers

Specifying JsonSerializerOptions in .NET 6 isolated Azure Function

I'm trying to call a Web API from code in an Azure Function that I've just ported to .NET 6 (isolated hosting model). I took the chance of the migration to get rid of the RestSharp and Json.NET dependencies, now only just using HttpClient and…
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
7
votes
1 answer

Serialising BigInteger using System.Text.Json

I'm serialising a BigInteger to JSON using System.Text.Json: JsonSerializer.Serialize(new {foo = new BigInteger(ulong.MaxValue) + 1}) This results in the following…
Neo
  • 4,145
  • 6
  • 53
  • 76
7
votes
2 answers

What's the setter of a built_value's object

I'm trying using built_value in flutter, and found if I declared a Type use built_value, I can commonly use dot syntax to assign value to it's properties: my declaration is: abstract class Post implements Built { Post._(); …
walker
  • 627
  • 1
  • 6
  • 19
1
2 3
20 21