小编n4z*_*4zg的帖子

改装抛出错误预计BEGIN_ARRAY但是BEGIN_OBJECT

嗨,我是Retrofit库的新手,我在解析一些json时遇到问题.我已经在Stackoverflow上看了一些其他的解决方案,但我的问题没有太多运气.我试图让一个简单的Web服务工作.任何建议将不胜感激..

Json文件

{"employees":[
{"firstName":"John", "lastName":"Doe"}, 
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
Run Code Online (Sandbox Code Playgroud)

请求方法

public void requestEmployeeData(String uri){
        RestAdapter adapter = new RestAdapter.Builder().setEndpoint(ENDPOINT).build();
        EmployeesAPI employeesAPI =adapter.create(EmployeesAPI.class);
        employeesAPI.getEmployees(new Callback<List<Employees.employeesclass>>() {
            @Override
            public void success(List<Employees.employeesclass> employees, Response response) {
                List<String> names = new ArrayList<String>();
                Log.v("nas", "The Employees Webservice Success" + response);
            }

            @Override
            public void failure(RetrofitError retrofitError) {
                Log.v("nas", "The Employees Webservice Failed " + retrofitError);
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

Employees.java

public class Employees {
// List<String> listOfStrings = new ArrayList<String>();
@SerializedName(value="employees")
public List<Employees> employees;

public …
Run Code Online (Sandbox Code Playgroud)

android json gson retrofit

7
推荐指数
1
解决办法
1万
查看次数

使用 JSON 数据在 html 中填充 ul

嗨,我正在尝试使用 JSON 填充 html 中的 ul,我已经尝试了该站点的许多解决方案,但我运气不佳,任何建议将不胜感激。谢谢

我的代码:

<script>
$.getJSON('/simplepie/round/alltables.json', function (data) {
var o = null;
var myArray = new Array();
document.open(); 
for( var i = 0; i < data.length; i++ )
{ 
    o = data[i];
    myArray.push('<li>' + o.title + '</li>');
    //document.write(o.source + " <br>" + o.description + "<br>") ;
    myArray.push(o.source);
    makeUL(o.source);
} 

//document.close();
// document.write('Latitude: ' + data.id + '\nLongitude: ' + data.title + '\nCountry: ' + data.description);

function makeUL(array) {
    var list = document.createElement('ul');
    for(var i = 0; …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json html-lists

4
推荐指数
1
解决办法
9163
查看次数

获取SectionList项目的索引React-Native

我在从SectionList React-Native 获取标题项的索引时遇到问题。通过按标题,我尝试获取该项目的索引,然后将其传递给函数。我尝试了很多事情但没有运气。有什么建议。谢谢

在此输入图像描述

我想按 3-30pm 返回索引 0 我可以按 Lucian,它返回我 0 这个想法是通过获取标题索引,我可以使用数组来从列表中删除项目。

            <SectionList style = {styles.itemSquare}

        renderItem = {({item, index, section}) =>
            < Text style={styles.SectionListItemStyle} key = {index}
            onPress={this.GetSectionListItem.bind(this, this.state.slotkeys[index])}> {item}
            < /Text>}

            renderSectionHeader = {({section: {title}, index}) => (
                  <TouchableHighlight >
                    <View>
                      <Text style={styles.SectionHeaderStyle}
                      onPress={this.GetSectionListItem.bind(this, index)}
                      > {title}
                      <Text style={styles.SectionHeaderCancel} > {index} < /Text>
                      </Text>
                    </View>
                  </TouchableHighlight>
                )
            }

          sections = {this.state.slots.map(({ time, chosen_user, name, chosen_syllabud, user_id }) =>
          ({ title: time, data: [[chosen_user], [chosen_syllabud], [user_id]], index:1 }))}

          keyExtractor = …
Run Code Online (Sandbox Code Playgroud)

javascript react-native react-native-sectionlist

1
推荐指数
1
解决办法
4066
查看次数