7

I am starting the development on windows phone 8, the famous JSON.NET does not support windows phone 8 yet, is there any other library which can be used for this purpose?

Undo
  • 25,519
  • 37
  • 106
  • 129
TilalHusain
  • 1,006
  • 5
  • 17
  • 36
  • The Windows Phone 7 version of Json.NET works on WP8. – James Newton-King Nov 06 '12 at 23:02
  • 1
    @JamesNewton-King, I tried adding the JSON.NET TO my project using NuGet and got "Could not install package 'Newtonsoft.Json 4.5.10'. You are trying to install this package into a project that targets 'WindowsPhone,Version=v8.0', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package author." – TilalHusain Nov 07 '12 at 07:14
  • The developer of JSON.NET answered your question ! kindly retry ! – Apoorv Sep 04 '15 at 09:16

5 Answers5

15

The JSON.NET codeplex site says that WP8 is supported.

Update: The JSON.NET NuGet package should just work with a Windows Phone 8.0 project. Adding it in VS2012 NuGet manager pulls in the WP7 version of JSON.NET. (packages\Newtonsoft.Json.4.5.10\lib\sl3-wp\Newtonsoft.Json.dll)

JSON.NET is now also available as a Portable Class Library which you can consume from WP8 (available in NuGet or in source form).

Paul Annetts
  • 9,554
  • 1
  • 27
  • 43
  • 3
    Here is what I got when installing via NuGet "Could not install package 'Newtonsoft.Json 4.5.10'. You are trying to install this package into a project that targets 'WindowsPhone,Version=v8.0', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package author." – TilalHusain Nov 07 '12 at 07:14
  • 1
    This worked fine for me on a brand new C# Windows Phone 8.0 project. It's picking up "packages\Newtonsoft.Json.4.5.10\lib\sl3-wp\Newtonsoft.Json.dll", i.e. the WP7 version of JSON.NET. I'll update my answer. – Paul Annetts Nov 07 '12 at 10:11
  • 3
    If this isn't working for anyone. Upgrade NuGet. With the newest version of NuGet I was able to install Json.Net. – mfperzel Dec 21 '12 at 18:59
  • For all newbies (like me) -> Visual Studio -> Project -> Manage NuGet Packages -> Online. There you should find it. If not use the search box on top right. – WarrenFaith Jun 07 '13 at 14:20
8

Had the exact same problem - turns out I didn't have the newest version of NuGet.

To upgrade, click tools -> extensions and updates and then click the Updates-tab. Update everything, restart the program and try again. :-)

Kris Selbekk
  • 7,438
  • 7
  • 46
  • 73
  • 1
    This is what solved the "You are trying to install this package into a project that targets 'WindowsPhone,Version=v8.0'" issue for me. This affected me even though I only downloaded the VS tools from Microsoft today; they seem to come with older versions of the tools. – Craig Russell Jun 07 '13 at 08:29
4

I was having this issue. I was able to compile the source for Windows Phone 8 instead of Windows 7.1 and it worked. NuGet would not work for me.

Here is how I did it:

  1. Open up solution JsonXXrXX.zip\Source\Src\Newtonsoft.JSON.WindowsPhone.sln
  2. Go to properties for Newtonsoft.Json.WindowsPhone Project(Right click on the project then properties)
  3. For the dropdown of "Target Windows Phone OS Version" select Windows 8.X
  4. Compile.
  5. Grab the DLL, PDB, and XML from the output directory
  6. Add Reference to the DLL file in your Windows Phone 8 Project

Thats it. I can't vouch that it works 100% or that you'll be able to submit your app. But it should hold you over until there is official support.

mfperzel
  • 4,924
  • 1
  • 18
  • 13
1

For complex json you might find this website helpful: http://json2csharp.com/#.

carlin.scott
  • 6,214
  • 3
  • 30
  • 35
0

If you don't wanna make too fancy stuff (or need dictionary) suppport, you can also just use the built-in DataContractJsonSerializer (http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx)

Btw: At least in https://json.codeplex.com/discussions/401305 some people report that the WP7.1 dll works for them, using this file: "Newtonsoft.Json.4.5.7\lib\sl4-windowsphone71\Newtonsoft.Json.dll".

Marco
  • 2,190
  • 15
  • 22
  • Thanks for the reply, Can I parse Dynamic json using DataContractJsonSerializer? because I will be parsing very complex json and creating a separate class for each object seems hectic task – TilalHusain Nov 06 '12 at 15:53
  • No, if the JSON structure is getting complex, esp. dynamic data what most probably means that it's a dictionary object on code level, this is still not supported. – Marco Nov 06 '12 at 15:55
  • Ok, So I think I have to leave json for now, what about XML, can you please recommend any dynamic xml parsing library? Thanks – TilalHusain Nov 06 '12 at 15:57