Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the "paste Json class" in visual studio 2012 when clicking on Paste Special?

I am trying to use the past special feature in vs 2012 in order to generate c# class for my Json data. I downloaded the Json.New from NewtonSoft from Nuget and then added a new .cs class the copied my json data to clipboard but when I go to Edit-> Paste Special --> I can only see: Paste XML As Classes only the Paste Json as Classes feature is not showing. Any Suggestions? Thanks you in advance

This is what I am getting and please note that I have installed Newtonsoft.Json already:


(source: indevcogroup.com)

like image 561
Sam Avatar asked Aug 30 '13 06:08

Sam


People also ask

How do I get Paste Special in Visual Studio?

To do so, select Edit > Paste Special and choose either Paste JSON As Classes or Paste XML As Classes.


2 Answers

I created a new project, installed Newtonsoft.Json and added a class.

If you have your class file open, copy your Json data and choose Edit -> Paste Special you will see both the options:

Paste Special with Json Option

If you have some other kind of file open (e.g. app.config), you only see "Paste JSON as As Classes" (and it's greyed out)

Paste Special - 1 option and greyed out

It does seem a bit flaky though - sometimes I had to recopy the data before it would show up.

Try a) recopying your data b) playing around with what windows you've got open c) reinstalling the extension

like image 71
Gareth Avatar answered Oct 06 '22 17:10

Gareth


When selecting the Edit > Paste Special menu while in the code of a class file, make sure that the Visual Studio project that your class file is under has its 'Target Framework' set to:

.NET Framework 3.5+ for 'Paste JSON as Classes'

.NET Framework 4.5+ for 'Paste XML as Classes'

Otherwise these options do not appear.

The 'Target Framework' setting is under the Project Properties > Application.

like image 27
Sean M Avatar answered Oct 06 '22 17:10

Sean M