【问题标题】:Index (zero based) must be greater than or equal to zero unity索引(从零开始)必须大于或等于零单位
【发布时间】:2018-05-24 17:50:47
【问题描述】:

我需要这方面的帮助。它在我的 logcat 上说:

System.FormatException:索引(从零开始)必须大于或等于零且小于参数列表的大小。

这是我到目前为止所做的。

1.) string full_path = string.Format("{0} {1}",Application.streamingAssetsPath + path_with_extention_under_streaming_assets_folder);

2.) string full_path = string.Format("{0}/{1}",Application.streamingAssetsPath + path_with_extention_under_streaming_assets_folder);

3.) string full_path = string.Format("{0}",Application.streamingAssetsPath + path_with_extention_under_streaming_assets_folder);

所有这些都不起作用。我的 logcat 上仍然出现错误

这是我的实际代码:

// Load 2 (StreamingAssets).
public static string LoadJsonFromStreamingAssets(string path_with_extention_under_streaming_assets_folder)
{
    string json = null;
    try
    {
        //Android Platform
    #if UNITY_ANDROID

        string full_path = string.Format("{0}/{1}",Application.streamingAssetsPath + path_with_extention_under_streaming_assets_folder);

        // Android only use WWW to read file
        WWW reader = new WWW(full_path);
        while (!reader.isDone){}

        json = reader.text;

        // PK Debug 2017.12.11
        Debug.Log("STEP 1. ");
        Debug.Log(json);

        JsonData itemData = JsonMapper.ToObject(json);

        Debug.Log("STEP 2. ");

     #else
        string full_path = string.Format("{0}/{1}", Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder);
        StreamReader reader = new StreamReader(full_path);
        json = reader.ReadToEnd().Trim();
        reader.Close();
     #endif
    }
    catch (Exception e)
    {
        Debug.LogWarningFormat("Failed to Load.\n{0}\n{1}", e, path_with_extention_under_streaming_assets_folder);
    }
    return json;
}

【问题讨论】:

  • 3) 上面不应该给出那个错误,但是你为什么需要使用string.Format( )呢?

标签: c# android json unity3d assets


【解决方案1】:

我通过更改找到了解决方案:

string full_path = string.Format("{0}/{1}",Application.streamingAssetsPath + path_with_extention_under_streaming_assets_folder);

到这里:

string full_path = string.Format("{0}/{1}",Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder);

【讨论】:

  • 嗯...是的。您要求提供两个参数({0}{1}),然后尝试仅传递一个参数(“a”+“b”是一个--连接的--字符串)。所以当然解决方案是传递两个实际参数。
  • @Draco18s 是的。我真是太白痴了。哈哈哈对不起
猜你喜欢
  • 2016-07-02
  • 2011-07-16
  • 2012-12-29
  • 2011-12-19
  • 2011-04-18
  • 2013-09-26
  • 2016-07-03
  • 2023-04-11
相关资源
最近更新 更多