如何解析这个没有对象名称的Json

时间:2017-10-18 07:35:16

标签: android json

{ 
   "quote": "To understand the heart and mind of a person, look not at 
   what he has already achieved, but at what he aspires to.",
   "author": "Kahlil Gibran (1883-1931)"
 }

如何解析这个没有任何对象名称

3 个答案:

答案 0 :(得分:1)

解析json对象有不同的方法

简单方法

JSONObject myJson = new JSONObject(yourJsonString);
String quote = myJson. getString("quote");
String author = myJson. getString("author");

另一种推荐的方法是使用Gson解析json 为此,您可以参考以下链接

How to parse json parsing Using GSON in android

https://www.journaldev.com/2321/gson-example-tutorial-parse-json

答案 1 :(得分:0)

怎么做?

  • 如果您在代码中遇到psql -U USERNAME -h localhost,则可以使用{}对其进行解析。

  • 如果您在代码中遇到JSONObject,则可以使用[]对其进行解析。

  • 如果您在代码中遇到JSONArray,则可以使用[]获取价值。

  • 您应该在代码中使用for loop

试试这个。

try catch

答案 2 :(得分:0)

这绝对是正常的json。

public partial class AddOnDeleteSetNull : DbMigration
{
    public override void Up()
    {
        Sql("ALTER TABLE dbo.TableA DROP CONSTRAINT [FK_dbo.TableA_dbo.Users_UserModifiedId]");
        Sql("ALTER TABLE dbo.TableA ADD CONSTRAINT [FK_dbo.TableA_dbo.Users_UserModifiedId_SetNullOnDelete] FOREIGN KEY (UserModifiedId) REFERENCES dbo.Users(UserId) ON UPDATE NO ACTION ON DELETE SET NULL");
    }

    public override void Down()
    {
        // Here you have to undo the changes!
        // ...
    }
}