Additional Destinations for Singapore Trip



More details -

Work with JSON Object in C#


From js code I’ve made a post call to c# webApi passing an array of objects.
Note that $ (angular) cannot pass array, hence I wrapped this in an object:
$ = {}; $ = $scope.LoggerServers;
[Object, Object] then became: Object {servers: Array[2]}

On c# side, I want to work on this as it is and then update the properties here and then return the $ object as it is….
For this I used:
public HttpResponseMessage Post(JObject serverList)
// try
// {
Log.Info(“Request for getting Logging Status by {1}”, GwmContext.RequestedBy.Name);
var a = serverList.GetValue(“servers”);
foreach (var serverInfo in a)

string s2 = serverList.ToString();
dynamic d = JObject.Parse(s2);
d.servers[0].server = “test”;

PS: Somehow, my webApi didn’t work when i took a string:
public dynamic Post(string serverList)
{ }
Hence i had to take a JObject OR Dynamic…
with JObject, i had to convert it to string first (using toString()) and then JObject.Parse() it,

Hence it’s better to take it as Dynamic directly in the parameter list…
On debugging, it shows that the dynamic object is of the type Array of Objects…(note that from JS i passed an array of objects only…)

ALSO note that now, i just change the properties on the Dynamic object, and then return it, and the best thing is that in js, i don’t have to worry about where to store it, as it matches the passed object perfectly:

$‘/a/api/Logger’, $scope.MyArrayOfObjects).success(function(data, status, headers, config) {
$scope.MyArrayOfObjects = data; // This simply gives me the modified $scope.MyArrayOfObjects cleanly