Himani Talesara
Himani Talesara

Reputation: 305

Json parsing using JSON.parse

I want to parse the following json strings. I am trying it with JSON.parse(jsonstring) but it repeatedly giving the following error.

SyntaxError: Unexpected token .

My Json strings are:

"SolutionData":"
Ch3LU3Ex1/Ch3LU3Ex1/Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{/*
     Write a program by using Regular Expression to check that the name of the user contains only alphabets. 

    If not, display the message "Invalid User Name".
*/
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

"

and 

"SolutionData":"
Ch3LU3Ex1/Ch3LU3Ex1/Properties/AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ConsoleApplication1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApplication1")]
[assembly: AssemblyCopyright("Copyright ©  2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bc2356b7-7c1e-467a-8bd7-8c6909e80623")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

"

Please help me how to do it.. I am trying hard of it but with no luck.Please help me.

Upvotes: 0

Views: 155

Answers (2)

mateusz.fiolka
mateusz.fiolka

Reputation: 3100

You can use the following site to valide your json: http://jsonlint.com/

Because your have a list of properties, you will need to wrap your code with { at the beginning and } at end.

Upvotes: 1

Boris Strandjev
Boris Strandjev

Reputation: 46953

New line is not a valid character in JSON string. I suggest you use online validator to get your JSONs right - until they are invalid you will not be able to parse them.

New line in json is written with \n. See here.

Upvotes: 1

Related Questions