0

我想解析以下 json 字符串。我正在尝试使用 JSON.parse(jsonstring) 但它反复给出以下错误。

SyntaxError: Unexpected token 。

我的 Json 字符串是:

"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")]

"

请帮我怎么做。我正在努力,但没有运气。请帮助我。

4

2 回答 2

1

您可以使用以下站点来验证您的 json:http: //jsonlint.com/

因为您有一个属性列表,所以您需要用 { 开头和 } 结尾来包装您的代码。

于 2013-03-01T13:29:48.430 回答
1

新行不是 JSON 字符串中的有效字符。我建议您使用在线验证器来获取正确的 JSON - 在它们无效之前,您将无法解析它们。

json 中的新行是用\n. 见这里

于 2013-03-01T13:30:49.760 回答