我使用 PHP 作为中间人来访问 MySql 数据库,它使用 json 字符串返回查询结果json_encode
,然后在应用程序的 TableLayout 中显示它,这就是为什么顺序很重要,所以我可以排列数据和标题。
经过一些研究,我发现 json 不强制执行顺序,所以任何时候我调用new JSONArray(result)
它都会打乱 PHP 返回的 json。有没有办法保留返回字符串的顺序?或者我在两端使用了不正确的数据结构。
相关PHP结果:
[{"FIELD1":"vsa","FIELD2":"dfs","FIELD3":"dsfa","FIELD4":"adsf","FIELD5":"23","ZIPCODE":"asdf","USERNAME":"asd","PASSWORD":"as","DATE1":"dsfa"}]
JSONArray(结果)之后的相关Android结果:
[{"ZIPCODE":"asdf","DATE1":"dsfa","FIELD3":"dsfa","FIELD2":"dfs","FIELD5":"23","FIELD4":"adsf","USERNAME":"asd","FIELD1":"vsa","PASSWORD":"as"}]