How do I parse nested JSON object?

When working in a .net environment, is appending a JSON file with .js a common good practice?

  • I have used JSON only in PHP environments and never had a problem with dynamically generated content. But when building a recent site in a .net environment, the data was not being passed through. I found out that the server will parse JSON and return in a different format. So something should be set up on the server to make sure that JSON is being parsed properly. I found this article on Microsoft's website that gage a tutorial on JSON: http://msdn.microsoft.com/en-us/library/bb299886.aspx But when I brought this up to other devs, one mentioned that he just renames his JSON file to a JavaScript file. I tried it, it works totally fine. So why would anyone do the lengthy way described in various tutorials throughout the web? or implement anything else. I am guessing that this (renaming as a JavaScript file) is just a hack and there might be other downfalls? Anyone else interested in reading about JSON, here are some links that are out there: http://www.codeproject.com/Articles/159450/fastJSON http://json.codeplex.com/

  • Answer:

    File content types are inferred by the file extensions. The .json file extension is likely not recognized, as opposed to the common .js extension. Try mapping .json to application/json on the server. The client application should receive the Content-Type header and handle it appropriately. Only as a last resort I'd suggest muddling the file extension to appear as JavaScript -- because it technically isn't.

Rick Viscomi at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.