How to fix problem with asp.net mvc 3 and json « « Digital Tool Factory blog

How to fix problem with asp.net mvc 3 and json

The Problem: You are attempting to import json data into your web application, but you continue to get weird errors.  Here is what the json data looked like

[{"entry":{"tags":[{"name":"Web Development","billable":true,"id":117906}],”created_at”:”2011-02-04T01:00:28Z”,”billable”:true,”minutes”:150,”updated_at”:”2011-02-04T01:00:40Z”,”recently_updated_at”:”2011-02-04T01:00:40Z”,”project_id”:40401,”import_id”:null,”url”:null,”time_to”:null,”id”:670893,”date”:”2011-02-02″,”user_id”:12914,”formatted_description”:”",”description_text”:”",”time_from”:null,”description”:”Web Development”,”invoiced_at”:null,”project_invoice_id”:null}},{“entry”:{“tags”:[{"name":"Web Development","billable":true,"id":117906}],”created_at”:”2011-02-04T01:04:42Z”,”billable”:true,”minutes”:180,”updated_at”:”2011-02-04T01:04:42Z”,”recently_updated_at”:”2011-02-04T01:04:42Z”,”project_id”:40401,”import_id”:null,”url”:null,”time_to”:null,”id”:670909,”date”:”2011-02-01″,”user_id”:12914,”formatted_description”:”",”description_text”:”",”time_from”:null,”description”:”Web Development”,”invoiced_at”:null,”project_invoice_id”:null}},{“entry”:{“tags”:[{"name":"Web Development","billable":true,"id":117906}],”created_at”:”2011-02-04T01:11:13Z”,”billable”:true,”minutes”:60,”updated_at”:”2011-02-04T01:11:13Z”,”recently_updated_at”:”2011-02-04T01:11:13Z”,”project_id”:40401,”import_id”:null,”url”:null,”time_to”:null,”id”:670914,”date”:”2011-01-31″,”user_id”:12914,”formatted_description”:”",”description_text”:”",”time_from”:null,”description”:”Web Development”,”invoiced_at”:null,”project_invoice_id”:null}}]

The Cause: The json is not in the format you think it should be in  While it looks like you would get each record back, you get one solid blob.

The Solution: Just remove the “[{“entry”:” and final “}”.  Ordinarily I wouldn’t make a big deal of this, but it did take me more than 30 minutes to figure out the cause of the problem, so here it is.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog

About the author

Steve French Steve is the President and lead developer of Digital Tool Factory and currently provides all technical development for DTF. Digital Tool Factory has provided behind the scenes technical muscle to the Atlanta design community since 2002.Google+ Profile

 

Written By Steve French

 

Leave a Reply





Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.