1

I have a JSON string as follows:

{
  "id" : "f_372484",
  "vertical" : "furniture",
  "title" : "George NAKASHIMA Rocking Chair",
  "description" : "Walnut Rocking chair with bowed horizontal crestrail over spindle back. A great example of high quality workmanship of George Nakashima (1905-1990).",
  "dealerReference" : "",
  "dibsReference" : "U1001058575397",
  "dateAdded" : "2010-03-12T10:58:59.000-05:00",
  "dateSold" : "2010-01-27T12:33:48.000-05:00",
  "releaseDate" : "1969-12-31T19:00:00.000-05:00",
  "modifiedDate" : "2014-02-08T22:41:15.000-05:00",
  "uploadType" : "USER",
  "status" : {
    "productStatus" : "SOLD",
    "contactForPrice" : "N",
    "locked" : "N",
    "posted" : "Y",
    "newListing" : "N",
    "inSaturdaySale" : "N",
    "isAvailable" : "N",
    "saveReleaseLater" : "N"
  },
  "dealerInternalNotes" : "",
  "pickupAddress" : "same",
  "overrideShipping" : "N",
  "pieces" : 1,
  "material" : {
    "description" : "Carved Walnut",
    "restricted" : "N"
  },
  "customMaterial" : {
    "restricted" : "N",
    "description" : "Carved Walnut"
  },
  "seller" : {
    "id" : "f_8575",
    "status" : "suspended"
  },
  "classification" : {
    "style" : { },
    "countryOfOrigin" : "USA",
    "categories" : [ "A14" ],
    "creationDate" : "Mid 20th C",
    "inflatedCategories" : [ [ {
      "key" : "f_",
      "name" : "Furniture",
      "label" : "furniture",
      "code" : "FURNITURE",
      "active" : "Y"
    }, {
      "key" : "f_A",
      "name" : "Seating",
      "label" : "seating",
      "code" : "A",
      "priority" : 1,
      "active" : "Y",
      "parent" : "f_"
    }, {
      "key" : "f_A14",
      "name" : "Rocking Chairs",
      "label" : "rocking-chairs",
      "code" : "A14",
      "priority" : 1,
      "active" : "Y",
      "parent" : "f_A"
    } ] ],
    "period" : "_1950"
  },
  "condition" : {
    "description" : "Very Good. ",
    "damageLosses" : "N",
    "damageLight" : "N",
    "damageSound" : "N",
    "damageFading" : "N"
  },
  "images" : [ {
    "position" : 1,
    "status" : "DONE",
    "thumb" : "/archivesD/upload/8575/397/dsc06990_1-02.jpg",
    "small" : "/archivesD/upload/8575/397/dsc06990_1-01.jpg",
    "medium" : "/archivesD/upload/8575/397/dsc06990_1-02.jpg",
    "large" : "/archivesD/upload/8575/397/dsc06990_1.jpg"
  }, {
    "position" : 2,
    "thumb" : "/archivesD/upload/8575/397/dsc06993-01.jpg",
    "large" : "/archivesD/upload/8575/397/dsc06993.jpg"
  }, {
    "position" : 3,
    "thumb" : "/archivesD/upload/8575/397/dsc06994-01.jpg",
    "large" : "/archivesD/upload/8575/397/dsc06994.jpg"
  }, {
    "position" : 4,
    "thumb" : "/archivesD/upload/8575/397/dsc06991-01.jpg",
    "large" : "/archivesD/upload/8575/397/dsc06991.jpg"
  }, {
    "position" : 5,
    "thumb" : "/archivesD/upload/8575/397/dsc06992-01.jpg",
    "large" : "/archivesD/upload/8575/397/dsc06992.jpg"
  }, {
    "position" : 6,
    "thumb" : "/archivesD/upload/8575/398/dsc06989-01.jpg",
    "large" : "/archivesD/upload/8575/398/dsc06989.jpg"
  }, {
    "position" : 7
  }, {
    "position" : 8
  }, {
    "position" : 9
  }, {
    "position" : 10
  } ],
  "pricing" : {
    "currency" : "USD",
    "amount" : 6800.0,
    "pricePerPiece" : "N",
    "negotiable" : "Y",
    "hidePrice" : "N",
    "bargain" : "N",
    "qualifyForBargain" : "N",
    "initialPrice" : 6800,
    "initialPriceCurrencies" : {
      "USD" : 6800.00,
      "PND" : 3944.00,
      "EUR" : 4896.00
    },
    "amountCurrencies" : {
      "USD" : 6800.00,
      "PND" : 3944.00,
      "EUR" : 4896.00
    }
  }
}

I am using the library from : http://james.newtonking.com/json
to parse JSON and to update properties of the object.

dynamic jsonObj = JObject.Parse(json);
dynamic furnitureItem = jsonObj.result.furnitureItem;

furnitureItem.title = "Hello";
furnitureItem.description = "World";

However after updating the properties the date value changes.

furnitureItem.ToString();//I am using this line to get updated JSON

JSON:

{
  "id": "f_372484",
  "vertical": "furniture",
  "title": "Hello",
  "description": "World",
  "dealerReference": "",
  "dibsReference": "U1001058575397",
  "dateAdded": "2010-03-12T21:28:59+05:30",
  "dateSold": "2010-01-27T23:03:48+05:30",
  "releaseDate": "1970-01-01T05:30:00+05:30",
  "modifiedDate": "2014-02-08T22:41:15.000-05:00",
  "uploadType": "USER",
  "status": {
    "productStatus": "UNRELEASED",
    "contactForPrice": "N",
    "locked": "N",
    "posted": "Y",
    "newListing": "N",
    "inSaturdaySale": "N",
    "isAvailable": "N",
    "saveReleaseLater": "N"
  },
  "dealerInternalNotes": "",
  "pickupAddress": "same",
  "overrideShipping": "N",
  "pieces": 1,
  "material": {
    "description": "Carved Walnut",
    "restricted": "N"
  },
  "customMaterial": {
    "restricted": "N",
    "description": "Carved Walnut"
  },
  "seller": {
    "id": "f_8575",
    "status": "suspended"
  },
  "classification": {
    "style": {},
    "countryOfOrigin": "USA",
    "categories": [
      "A14"
    ],
    "creationDate": "Mid 20th Century",
    "inflatedCategories": [
      [
        {
          "key": "f_",
          "name": "Furniture",
          "label": "furniture",
          "code": "FURNITURE",
          "active": "Y"
        },
        {
          "key": "f_A",
          "name": "Seating",
          "label": "seating",
          "code": "A",
          "priority": 1,
          "active": "Y",
          "parent": "f_"
        },
        {
          "key": "f_A14",
          "name": "Rocking Chairs",
          "label": "rocking-chairs",
          "code": "A14",
          "priority": 1,
          "active": "Y",
          "parent": "f_A"
        }
      ]
    ],
    "period": "_1950"
  },
  "condition": {
    "description": "Very Good. ",
    "damageLosses": "N",
    "damageLight": "N",
    "damageSound": "N",
    "damageFading": "N"
  },
  "images": [
    {
      "position": 1,
      "status": "DONE",
      "thumb": "/archivesD/upload/8575/397/dsc06990_1-02.jpg",
      "small": "/archivesD/upload/8575/397/dsc06990_1-01.jpg",
      "medium": "/archivesD/upload/8575/397/dsc06990_1-02.jpg",
      "large": "/archivesD/upload/8575/397/dsc06990_1.jpg"
    },
    {
      "position": 2,
      "thumb": "/archivesD/upload/8575/397/dsc06993-01.jpg",
      "large": "/archivesD/upload/8575/397/dsc06993.jpg"
    },
    {
      "position": 3,
      "thumb": "/archivesD/upload/8575/397/dsc06994-01.jpg",
      "large": "/archivesD/upload/8575/397/dsc06994.jpg"
    },
    {
      "position": 4,
      "thumb": "/archivesD/upload/8575/397/dsc06991-01.jpg",
      "large": "/archivesD/upload/8575/397/dsc06991.jpg"
    },
    {
      "position": 5,
      "thumb": "/archivesD/upload/8575/397/dsc06992-01.jpg",
      "large": "/archivesD/upload/8575/397/dsc06992.jpg"
    },
    {
      "position": 6,
      "thumb": "/archivesD/upload/8575/398/dsc06989-01.jpg",
      "large": "/archivesD/upload/8575/398/dsc06989.jpg"
    },
    {
      "position": 7
    },
    {
      "position": 8
    },
    {
      "position": 9
    },
    {
      "position": 10
    }
  ],
  "pricing": {
    "currency": "USD",
    "amount": 6800.0,
    "pricePerPiece": "N",
    "negotiable": "Y",
    "hidePrice": "N",
    "bargain": "N",
    "qualifyForBargain": "N",
    "initialPrice": 6800,
    "initialPriceCurrencies": {
      "USD": 6800.0,
      "PND": 3944.0,
      "EUR": 4896.0
    },
    "amountCurrencies": {
      "USD": 6800.0,
      "PND": 3944.0,
      "EUR": 4896.0
    }
  }
}

I want to keep the date value as it is
do not want to change timezone which is happening automatically.

1

2 Answers 2

1

If you don't plan to work with dates, you can preserve them as strings.

JsonReader jsonReader = new JsonTextReader(new StringReader(json)) { DateParseHandling = DateParseHandling.None };
dynamic jsonObj = JObject.Load(jsonReader);
Sign up to request clarification or add additional context in comments.

Comments

0

Here's the documentation page from JSON.NET which shows you how to control the format of serialized Dates: http://james.newtonking.com/json/help/index.html?topic=html/DatesInJSON.htm

From the documentation:

// default as of Json.NET 4.5
string isoJson = JsonConvert.SerializeObject(entry);
    // {"Details":"Application started.","LogDate":"2009-02-15T00:00:00Z"}

JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings
{
    DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
};

string microsoftJson = JsonConvert.SerializeObject(
    entry, microsoftDateFormatSettings);
    // {"Details":"Application started.","LogDate":"\/Date(1234656000000)\/"}

string javascriptJson = JsonConvert.SerializeObject(
    entry, new JavaScriptDateTimeConverter());
    // {"Details":"Application started.","LogDate":new Date(1234656000000)}

1 Comment

Hi @pptitle, thank for reply, I am not using the deserialize function anywhere in my code, similar issue: link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.